@veltdev/tiptap-velt-comments
Version:
Tiptap Extension to add Google Docs-style overlay comments to your Tiptap editor. Works with the Velt Collaboration SDK.
3 lines (2 loc) • 22.2 kB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@tiptap/core"),e=function(){return e=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var r in e=arguments[n])Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t},e.apply(this,arguments)};function n(t,e,n,o){return new(n||(n=Promise))(function(r,i){function a(t){try{c(o.next(t))}catch(t){i(t)}}function d(t){try{c(o.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,d)}c((o=o.apply(t,e||[])).next())})}function o(t,e){var n,o,r,i={label:0,sent:function(){if(1&r[0])throw r[1];return r[1]},trys:[],ops:[]},a=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return a.next=d(0),a.throw=d(1),a.return=d(2),"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function d(d){return function(c){return function(d){if(n)throw new TypeError("Generator is already executing.");for(;a&&(a=0,d[0]&&(i=0)),i;)try{if(n=1,o&&(r=2&d[0]?o.return:d[0]?o.throw||((r=o.return)&&r.call(o),0):o.next)&&!(r=r.call(o,d[1])).done)return r;switch(o=0,r&&(d=[2&d[0],r.value]),d[0]){case 0:case 1:r=d;break;case 4:return i.label++,{value:d[1],done:!1};case 5:i.label++,o=d[1],d=[0];continue;case 7:d=i.ops.pop(),i.trys.pop();continue;default:if(!(r=i.trys,(r=r.length>0&&r[r.length-1])||6!==d[0]&&2!==d[0])){i=0;continue}if(3===d[0]&&(!r||d[1]>r[0]&&d[1]<r[3])){i.label=d[1];break}if(6===d[0]&&i.label<r[1]){i.label=r[1],r=d;break}if(r&&i.label<r[2]){i.label=r[2],i.ops.push(d);break}r[2]&&i.ops.pop(),i.trys.pop();continue}d=e.call(t,i)}catch(t){d=[6,t],o=0}finally{n=r=0}if(5&d[0])throw d[1];return{value:d[0]?d[1]:void 0,done:!0}}([d,c])}}}"function"==typeof SuppressedError&&SuppressedError;var r={EDITOR_ID:"data-editor-id",LOCATION_ID:"data-velt-location-id"},i=function(){function t(){}var n;return n=t,t.selectedCommentsMap=new Map,t.subscribers=new Map,t.isSubscribed=!1,t.getCommentElement=function(){try{var t=window.Velt;return(null==t?void 0:t.getCommentElement)?t.getCommentElement():null}catch(t){return n.catchError("Error getting comment element:",t),null}},t.addManualComment=function(t){var e=t.context,o=t.location;try{var r=n.getCommentElement();return r?r.addManualComment({context:e,location:o}):Promise.resolve(null)}catch(t){return n.catchError("Error adding manual comment:",t),Promise.resolve(null)}},t.updateContext=function(t){var e=t.annotationId,o=t.context;try{var r=n.getCommentElement();return r?r.updateContext(e,o):Promise.resolve(null)}catch(t){n.catchError("Error updating context:",t)}},t.subscribeToSelectedCommentsMap=function(t,e){try{n.subscribeToSelectedAnnotationsMapSingleton(),n.subscribers.set(t,e)}catch(t){n.catchError("Error subscribing to selected comments map:",t)}},t.unsubscribeFromSelectedCommentsMap=function(t){try{n.subscribers.delete(t)}catch(t){n.catchError("Error unsubscribing from selected comments map:",t)}},t.catchError=function(t,n){var o;try{var r={};n&&"object"==typeof n&&(r=e(e({},r),n)),t&&(r.message=t),r.sdkVersion=null===(o=window.Velt)||void 0===o?void 0:o.version}catch(t){}},t.subscribeToSelectedAnnotationsMapSingleton=function(){var t;try{if(n.isSubscribed)return;var e=n.getCommentElement();e&&"function"==typeof(null==e?void 0:e.getSelectedComments)&&(null===(t=null==e?void 0:e.getSelectedComments())||void 0===t||t.subscribe(function(t){var e=new Map;null==t||t.forEach(function(t){(null==t?void 0:t.annotationId)&&e.set(null==t?void 0:t.annotationId,!0)});(function(t,e){if(t.size!==e.size)return!1;for(var n=0,o=Array.from(t);n<o.length;n++){var r=o[n],i=r[0],a=r[1];if(e.get(i)!==a)return!1}return!0})(e,n.selectedCommentsMap||new Map)||n.updateSelectedCommentsMap(e)}),n.isSubscribed=!0)}catch(t){return new Map}},t.updateSelectedCommentsMap=function(t){try{n.selectedCommentsMap=t,n.subscribers.forEach(function(t){"function"==typeof t&&t(n.selectedCommentsMap)})}catch(t){n.catchError("Error updating selected comments map:",t)}},t}(),a=function(){function t(t){this.getSelectedText=function(t){var e;try{return(null===(e=t.state)||void 0===e?void 0:e.selection)?t.state.doc.textBetween(t.state.selection.from,t.state.selection.to):null}catch(t){return i.catchError("Error getting selected text:",t),null}},this.plugin=t}return t.prototype.findParentNodeWithId=function(t){try{for(var e=t.state.selection.from,n=t.view.domAtPos(e).node,o=t.view.dom,r=0,i=n;i&&i!==document.body&&r<100;){if(!o.contains(i))return null;if(i.id)return i;i=i.parentElement,r++}return null}catch(t){return null}},t.prototype.onTransaction=function(t){var e=t.editor,n=t.name;try{for(var o=new Map,r=this.collectDocumentAnnotations(e,n),a=0,d=Array.from(r.entries());a<d.length;a++){var c=d[a],l=c[0],u=c[1],s=this.processAnnotationChanges(e,u);s&&o.set(l,s)}if(o.size>0){var v=i.getCommentElement();if(!v)return;this.updateVeltComments(v,o,e)}}catch(t){i.catchError("Error on transaction:",t)}},t.prototype.collectDocumentAnnotations=function(t,e){var n=this;try{var o=new Map;return t.state.doc.descendants(function(t,r){var i,a,d,c,l,u,s=t;if(s.isText){var v=s.marks.find(function(t){return t.type.name===e});if(v){var f=v.attrs["annotation-id"];if("string"==typeof f){var m=v.attrs["multi-thread-annotation-id"],g=n.plugin.storeService.annotationStore.get(f);if(g){var h=o.get(f),p={node:{text:s.text||"",nodeSize:s.nodeSize},pos:r};h?h.nodes.push(p):o.set(f,{id:f,multiThreadAnnotationId:m,annotation:g.annotation,nodes:[p],originalText:(null===(a=null===(i=g.annotation.context)||void 0===i?void 0:i.textEditorConfig)||void 0===a?void 0:a.text)||"",originalOccurrence:(null===(c=null===(d=g.annotation.context)||void 0===d?void 0:d.textEditorConfig)||void 0===c?void 0:c.occurrence)||1,targetTextNodeId:(null===(u=null===(l=g.annotation.context)||void 0===l?void 0:l.textEditorConfig)||void 0===u?void 0:u.targetTextNodeId)||""})}}}}}),o}catch(t){return new Map}},t.prototype.detectContentChanges=function(t,e){var n=function(t,e,n){if(n||2===arguments.length)for(var o,r=0,i=e.length;r<i;r++)!o&&r in e||(o||(o=Array.prototype.slice.call(e,0,r)),o[r]=e[r]);return t.concat(o||Array.prototype.slice.call(e))}([],t,!0).sort(function(t,e){return t.pos-e.pos}),o=n.map(function(t){return t.node.text||""}).join("");return{currentText:o,contentChanged:o!==e}},t.prototype.detectContainerChanges=function(t,e){var n=e.annotationId,o=e.currentText,r=e.targetTextNodeId,i=e.nodes,a=!1,d=r,c=[],l=this.processContainerChanges(t,{annotationId:n,currentText:o,targetTextNodeId:r,nodes:i});return l?(a=l.changed,d=l.newId,c=l.searchResults):c=r?this.findTextInDomElement(t,o,r):this.findTextInDocument(t,o),{targetTextNodeIdChanged:a,newTargetTextNodeId:d,searchResults:c}},t.prototype.createAnnotationChange=function(t,e){var n=e.currentText,o=e.contentChanged,r=e.currentOccurrence,i=e.occurrenceChanged,a=e.targetTextNodeIdChanged,d=e.newTargetTextNodeId;return{annotationId:t.id,multiThreadAnnotationId:t.multiThreadAnnotationId,originalText:t.originalText,currentText:o?n:t.originalText,originalOccurrence:t.originalOccurrence,currentOccurrence:r,originalTargetTextNodeId:t.targetTextNodeId,newTargetTextNodeId:a?d:t.targetTextNodeId,annotation:t.annotation,contentChanged:o,occurrenceChanged:i,targetTextNodeIdChanged:a}},t.prototype.processAnnotationChanges=function(t,e){try{if(!t||!e)throw new Error("Invalid input: editor and data are required");if(!e.originalText||!e.annotation)return null;if(!Array.isArray(e.nodes)||0===e.nodes.length)return null;var n=this.detectContentChanges(e.nodes,e.originalText),o=n.currentText,r=n.contentChanged,i=this.detectContainerChanges(t,{annotationId:e.id,currentText:o,targetTextNodeId:e.targetTextNodeId,nodes:e.nodes}),a=i.targetTextNodeIdChanged,d=i.newTargetTextNodeId,c=i.searchResults,l=this.calculateNewOccurrence(t,{searchResults:c,nodes:e.nodes,contentChanged:r,currentText:o,targetTextNodeId:a?d:e.targetTextNodeId,originalOccurrence:e.originalOccurrence}),u=l!==e.originalOccurrence;return r||u||a?this.createAnnotationChange(e,{currentText:o,contentChanged:r,currentOccurrence:l,occurrenceChanged:u,targetTextNodeIdChanged:a,newTargetTextNodeId:d}):null}catch(t){return null}},t.prototype.processContainerChanges=function(t,e){var n=e.annotationId,o=e.currentText,r=e.targetTextNodeId;if(!r)return null;var i=null;if(t.state.doc.descendants(function(t,e){t.marks.find(function(t){return"tiptapVeltComments"===t.type.name&&t.attrs["annotation-id"]===n})&&!i&&(i=e)}),null!==i){for(var a=t.view.domAtPos(i).node,d=t.view.dom;a&&!a.id&&a!==document.body&&(a=a.parentElement||a,d.contains(a)););if((null==a?void 0:a.id)&&a.id!==r){var c=this.findTextInDomElement(t,o,a.id);return{changed:!0,newId:a.id,searchResults:c}}}return null},t.prototype.calculateNewOccurrence=function(t,e){if(0===e.searchResults.length)return e.originalOccurrence;for(var n=e.nodes[0],o=e.nodes[e.nodes.length-1],r=n.pos,i=o.pos+(o.node.nodeSize||0),a=0;a<e.searchResults.length;a++){var d=e.searchResults[a];if(d.from<=r&&d.to>=r||d.from<=i&&d.to>=i||r<=d.from&&i>=d.to)return a+1}return e.originalOccurrence},t.prototype.updateVeltComments=function(t,n,o){var r;try{for(var a=0,d=Array.from(n.entries());a<d.length;a++){var c=d[a],l=c[0],u=c[1];try{if(!(null===(r=u.annotation.context)||void 0===r?void 0:r.textEditorConfig))continue;var s=JSON.parse(JSON.stringify(u.annotation.context.textEditorConfig));u.contentChanged&&(s.text=u.currentText),u.occurrenceChanged&&(s.occurrence=u.currentOccurrence),u.targetTextNodeIdChanged&&(s.targetTextNodeId=u.newTargetTextNodeId);var v=e(e({},u.annotation.context),{textEditorConfig:s});this.plugin.storeService.annotationStore.remove(l),this.plugin.editorService.removeVeltCommentFromEditor(o,l),i.updateContext({annotationId:l,context:v})}catch(t){}}}catch(t){}},t.prototype.computeKMPTable=function(t){try{for(var e=new Array(t.length).fill(0),n=0,o=1;o<t.length;)t[o]===t[n]?(n++,e[o]=n,o++):0!==n?n=e[n-1]:(e[o]=0,o++);return e}catch(t){return[]}},t.prototype.kmpSearch=function(t,e,n,o){void 0===n&&(n=0);try{var r=[];if(!e||!t||e.length>t.length)return r;for(var i=this.computeKMPTable(e),a=0,d=0;a<t.length;)if(e[d]===t[a]&&(a++,d++),d===e.length){if(r.push(n+a-d),d=i[d-1],o&&r.length>=o)break}else a<t.length&&e[d]!==t[a]&&(0!==d?d=i[d-1]:a++);return r}catch(t){return[]}},t.prototype.findTextInDomElement=function(t,e,n,o){var r;try{var i=[],a=document.getElementById(n);if(!a)return i;var d=t.view.posAtDOM(a,0);if(null===d)return i;var c=t.state.doc.resolve(d).pos,l=(null===(r=a.textContent)||void 0===r?void 0:r.length)||0,u=[];t.state.doc.nodesBetween(c,c+l,function(t,e){var n=t;n.isText&&u.push({text:n.text||"",pos:e})});for(var s=u.map(function(t){return t.text}).join(""),v=this.kmpSearch(s,e,0,o),f=0,m=v;f<m.length;f++){for(var g=m[f],h=0,p=-1,x=0,I=-1,C=0,T=0;T<u.length;T++){var b=u[T].text.length;if(-1===p&&g<h+b&&(p=T,x=g-h),-1===I&&g+e.length<=h+b){I=T,C=g+e.length-h;break}h+=b}if(-1!==p&&-1!==I){var y=u[p].pos+x,E=u[I].pos+C;if(i.push({from:y,to:E}),o&&i.length>=o)break}}return i}catch(t){return[]}},t.prototype.findTextInDocument=function(t,e,n){try{var o=[],r=t.state.doc,i=n||void 0,a=[];r.descendants(function(t,e){var n=t;n.isText&&a.push({text:n.text||"",pos:e})});for(var d=a.map(function(t){return t.text}).join(""),c=this.kmpSearch(d,e,0,i),l=0,u=c;l<u.length;l++){for(var s=u[l],v=0,f=-1,m=0,g=-1,h=0,p=0;p<a.length;p++){var x=a[p].text.length;if(-1===f&&s<v+x&&(f=p,m=s-v),-1===g&&s+e.length<=v+x){g=p,h=s+e.length-v;break}v+=x}if(-1!==f&&-1!==g){var I=a[f].pos+m,C=a[g].pos+h;if(o.push({from:I,to:C}),i&&o.length>=i)break}}return o}catch(t){return[]}},t.prototype.findOccurrenceIndex=function(t,e,n,o,r){try{if(!e.trim())return 1;var i=[];i=n&&n.id?this.findTextInDomElement(t,e,n.id):this.findTextInDocument(t,e);for(var a=0;a<i.length;a++)if(i[a].from===o&&i[a].to===r)return a+1;return 1}catch(t){return 1}},t.prototype.highlightTextWithVeltComment=function(t,e,n){var o,i,a,d,c,l;try{var u=n.targetTextNodeId,s=(null==n?void 0:n.occurrence)||1;if(n.annotationId){var v=this.plugin.storeService.annotationStore.get(n.annotationId);if(v){var f=null===(o=v.annotation.context)||void 0===o?void 0:o.textEditorConfig,m=null===(a=null===(i=n.originalAnnotation)||void 0===i?void 0:i.context)||void 0===a?void 0:a.textEditorConfig;f&&m&&(f.text!==m.text||f.occurrence!==m.occurrence||f.targetTextNodeId!==m.targetTextNodeId)&&this.removeVeltCommentFromEditor(t,n.annotationId)}}if(!e||0===e.length)return;if(u){var g=document.getElementById(u);if(g)if((null===(d=g.closest("[".concat(r.LOCATION_ID,"]")))||void 0===d?void 0:d.getAttribute(r.LOCATION_ID))!==(null===(l=null===(c=n.originalAnnotation)||void 0===c?void 0:c.location)||void 0===l?void 0:l.id))return}var h=[];if(0===(h=u?this.findTextInDomElement(t,e,u,s):this.findTextInDocument(t,e,s)).length)return;var p=h[Math.min(s,h.length)-1];p&&n.annotationId&&(this.plugin.storeService.annotationStore.set(n.annotationId,{annotation:n.originalAnnotation||{annotationId:n.annotationId,multiThreadAnnotationId:n.multiThreadAnnotationId,text:e},pluginReference:{node:document.createElement("velt-comment-text"),position:{from:p.from,to:p.to}}}),t.chain().focus().setVeltComment(n.annotationId,n.multiThreadAnnotationId,p.from,p.to).run())}catch(t){}},t.prototype.removeVeltCommentFromEditor=function(t,e){var n;try{if(!t||!e)throw new Error("Invalid input: editor and annotationId are required");var o=this.plugin.storeService.annotationStore.get(e);if(!(null===(n=null==o?void 0:o.pluginReference)||void 0===n?void 0:n.position))throw new Error("Invalid stored data for annotation");var r=o.pluginReference.position,i=r.from,a=r.to;if(i>=a)throw new Error("Invalid position range: from must be less than to");var d=t.schema.marks.tiptapVeltComments;if(!d)throw new Error("Velt comment mark type not found");var c=!1;return t.chain().focus().command(function(n){var o=n.tr;return t.state.doc.descendants(function(t,n){n<i||n>a||t.marks.find(function(t){return t.type===d&&t.attrs["annotation-id"]===e})&&(o.removeMark(n,n+t.nodeSize,d),c=!0)}),c}).run(),c}catch(t){return!1}},t.getEditorId=function(t){var e,n,o,a;try{if(!t)return null;var d=null===(n=null===(e=t.storage)||void 0===e?void 0:e.tiptapVeltComments)||void 0===n?void 0:n.editorId;if(d)return d;var c=t.view.dom;return c&&(null!==(a=null===(o=null==c?void 0:c.closest("[".concat(r.EDITOR_ID,"]")))||void 0===o?void 0:o.getAttribute(r.EDITOR_ID))&&void 0!==a)?a:null}catch(t){return i.catchError("Error finding editor ID:",t),null}},t}(),d=function(){function t(t){var n=this;this.isSubscribed=!1,this.globalStore={editor:null,comments:[],filteredComments:[],selectedCommentsMap:new Map},this.globalAnnotationStore=new Map,this.annotationStore={get:function(t){return n.globalAnnotationStore.get(t)},set:function(t,e){n.globalAnnotationStore.set(t,e)},getAll:function(){return new Map(n.globalAnnotationStore)},clear:function(){n.globalAnnotationStore.clear()},remove:function(t){n.globalAnnotationStore.delete(t)},hasAnnotationTextChanged:function(t,e){var o,r;try{var i=n.globalAnnotationStore.get(t);return!(!i||!e)&&i.annotation.text!==(null===(r=null===(o=e.context)||void 0===o?void 0:o.textEditorConfig)||void 0===r?void 0:r.text)}catch(t){return!1}}},this.updateGlobalStore=function(t){var o,r,a;try{var d=(null==t?void 0:t.comments)||(null===(o=n.globalStore)||void 0===o?void 0:o.comments)||[],c=(null==t?void 0:t.selectedCommentsMap)||(null===(r=n.globalStore)||void 0===r?void 0:r.selectedCommentsMap)||new Map,l=(null===(a=n.globalStore)||void 0===a?void 0:a.filteredComments)||[],u=d.filter(function(t){var e;return"terminal"!==(null===(e=null==t?void 0:t.status)||void 0===e?void 0:e.type)||(null==c?void 0:c.get(null==t?void 0:t.annotationId))}),s=new Set(u.map(function(t){return null==t?void 0:t.annotationId}));l.map(function(t){return null==t?void 0:t.annotationId}).filter(function(t){return t&&!s.has(t)}).forEach(function(t){var e,o;(null===(e=n.globalStore)||void 0===e?void 0:e.editor)&&t&&n.plugin.editorService.removeVeltCommentFromEditor(null===(o=n.globalStore)||void 0===o?void 0:o.editor,t)}),n.globalStore=e(e(e({},n.globalStore),t),{filteredComments:u}),n.highlightCommentsFromGlobalStore()}catch(t){i.catchError("Error updating global store:",t)}},this.highlightCommentsFromGlobalStore=function(){var t,e,o,r,a,d;try{var c=n.globalStore,l=c.editor,u=c.filteredComments;if(!l||!u)return;for(var s=0,v=u;s<v.length;s++){var f=v[s],m=null===(e=null===(t=null==f?void 0:f.context)||void 0===t?void 0:t.textEditorConfig)||void 0===e?void 0:e.text,g=null===(r=null===(o=null==f?void 0:f.context)||void 0===o?void 0:o.textEditorConfig)||void 0===r?void 0:r.occurrence;m&&n.plugin.editorService.highlightTextWithVeltComment(l,m,{annotationId:null==f?void 0:f.annotationId,multiThreadAnnotationId:null==f?void 0:f.multiThreadAnnotationId,occurrence:g,targetTextNodeId:null===(d=null===(a=null==f?void 0:f.context)||void 0===a?void 0:a.textEditorConfig)||void 0===d?void 0:d.targetTextNodeId,originalAnnotation:f})}}catch(t){i.catchError("Error highlighting comments from global store:",t)}},this.plugin=t;try{i.subscribeToSelectedCommentsMap(this.plugin.editorId,function(t){try{n.updateGlobalStore({selectedCommentsMap:t})}catch(t){i.catchError("Error updating global store:",t)}})}catch(t){i.catchError("Error subscribing to selected comments map:",t)}}return t.storeInstanceMap=new Map,t}(),c=new Map,l=function(){function t(t,e){this.editorId=t,this.editor=e,this.editorService=new a(this),this.storeService=new d(this)}return t.getInstance=function(e){var n=e||{},o=n.editorId,r=n.editor;return o||(o="default"),c.has(o)||c.set(o,new t(o,r)),c.get(o)},t}(),u=function(t,e){return n(void 0,void 0,void 0,function(){return o(this,function(n){try{return[2,s({editor:t,context:null==e?void 0:e.context})]}catch(t){i.catchError("Error triggering add comment",t)}return[2]})})},s=function(t){var d=t.editorId,c=t.editor,u=t.context;return n(void 0,void 0,void 0,function(){var t,n,s,v,f,m,g,h,p,x,I,C,T,b;return o(this,function(o){try{if(!(t=i.getCommentElement()))return[2];if(d||(d=null!==(C=a.getEditorId(c))&&void 0!==C?C:void 0),n=l.getInstance({editorId:d,editor:c}),!(s=n.editorService.getSelectedText(c)))return[2];if(v=n.editorService.findParentNodeWithId(c),f=void 0,m=void 0,v&&(f=v.id,m=null===(T=v.closest("[".concat(r.LOCATION_ID,"]")))||void 0===T?void 0:T.getAttribute(r.LOCATION_ID)),g=c.state.selection.from,h=c.state.selection.to,!(p=n.editorService.findOccurrenceIndex(c,s,v,g,h)))return[2];x={},u&&"object"==typeof u&&(x=e(e({},x),u)),x.textEditorConfig={text:s,occurrence:p,targetTextNodeId:f},d&&(x.textEditorConfig.editorId=d),I=void 0,m&&(I={id:m}),null===(b=null==t?void 0:t.addManualComment({context:x,location:I}))||void 0===b||b.then(function(t){var e,n;if(!c.storage.tiptapVeltComments.persistVeltMarks){var o=null===(e=null==t?void 0:t.annotation)||void 0===e?void 0:e.annotationId,r=null===(n=null==t?void 0:t.annotation)||void 0===n?void 0:n.multiThreadAnnotationId;c.chain().focus().setVeltComment(o,r).run()}c.chain().focus().run()})}catch(t){i.catchError("Error adding tiptap-velt-comments",t)}return[2]})})},v=u,f=t.Mark.create({name:"tiptapVeltComments",addOptions:function(){return{HTMLAttributes:{},persistVeltMarks:!0,editorId:void 0}},addStorage:function(){return{persistVeltMarks:this.options.persistVeltMarks,editorId:this.options.editorId}},parseHTML:function(){return[{tag:"velt-comment-text",getAttrs:function(t){return{"annotation-id":t.getAttribute("annotation-id"),"multi-thread-annotation-id":t.getAttribute("multi-thread-annotation-id")}}}]},renderHTML:function(e){var n=e.HTMLAttributes;return e.mark,["velt-comment-text",t.mergeAttributes(this.options.HTMLAttributes,n),0]},addAttributes:function(){return{"annotation-id":{default:null,parseHTML:function(t){return t.getAttribute("annotation-id")},renderHTML:function(t){return t["annotation-id"]?{"annotation-id":t["annotation-id"]}:{}}},"multi-thread-annotation-id":{default:null,parseHTML:function(t){return t.getAttribute("multi-thread-annotation-id")},renderHTML:function(t){return t["multi-thread-annotation-id"]?{"multi-thread-annotation-id":t["multi-thread-annotation-id"]}:{}}}}},addCommands:function(){var t=this;return{setVeltComment:function(e,n,o,r){return function(i){var a=i.tr,d=i.state,c=i.dispatch,l=void 0!==o?o:d.selection.from,u=void 0!==r?r:d.selection.to;if(c){var s={};return n?s["multi-thread-annotation-id"]=n:e&&(s["annotation-id"]=e),a.addMark(l,u,t.type.create(s)),!0}return!1}}}},onTransaction:function(t){var e,n=t.transaction,o=t.editor;try{if(!n.docChanged)return;if(!o.storage.tiptapVeltComments.persistVeltMarks)return;var r=this.editor.storage.tiptapVeltComments.editorId;r||(r=null!==(e=a.getEditorId(o))&&void 0!==e?e:void 0),l.getInstance({editorId:r,editor:o}).editorService.onTransaction({editor:o,name:this.name})}catch(t){}}});var m=function(t){var e,n,o=t.editor,r=t.editorId,d=t.commentAnnotations;try{if(o){if(r||(r=null!==(e=a.getEditorId(o))&&void 0!==e?e:void 0),!Array.isArray(d))return;var c=(null===(n=null==(d=JSON.parse(JSON.stringify(d)))?void 0:d.map(function(t){var e,n;return(null===(e=null==t?void 0:t.context)||void 0===e?void 0:e.tiptapConfig)&&!(null===(n=null==t?void 0:t.context)||void 0===n?void 0:n.textEditorConfig)&&(t.context.textEditorConfig=t.context.tiptapConfig,delete t.context.tiptapConfig),t}))||void 0===n?void 0:n.filter(function(t){var e,n,o;return!!(null===(e=t.context)||void 0===e?void 0:e.textEditorConfig)&&(null===(o=null===(n=t.context)||void 0===n?void 0:n.textEditorConfig)||void 0===o?void 0:o.editorId)===r}))||[];l.getInstance({editorId:r,editor:o}).storeService.updateGlobalStore({editor:o,comments:c}),i.subscribeToSelectedAnnotationsMapSingleton()}}catch(t){i.catchError("Error highlighting tiptap-velt-comments",t)}};exports.TiptapVeltComments=f,exports.addComment=s,exports.addTiptapVeltComment=v,exports.default=f,exports.highlightComments=function(t,e,n){try{m({editor:t,editorId:n,commentAnnotations:e})}catch(t){i.catchError("Error highlighting tiptap-velt-comments",t)}},exports.renderComments=m,exports.triggerAddComment=u;
//# sourceMappingURL=index.js.map