@veltdev/slate-velt-comments-staging 1.0.4 → 5.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/cjs/index.js +1 -1
  2. package/cjs/index.js.map +1 -1
  3. package/cjs/types/adapters/host/doc.d.ts +86 -0
  4. package/cjs/types/adapters/host/marks.d.ts +51 -0
  5. package/cjs/types/adapters/host/storage.d.ts +38 -0
  6. package/cjs/types/adapters/velt.d.ts +50 -0
  7. package/cjs/types/constants/common.d.ts +58 -0
  8. package/cjs/types/core/ExtensionComponent.d.ts +13 -0
  9. package/cjs/types/core/extension.d.ts +54 -0
  10. package/cjs/types/core/registry.d.ts +52 -0
  11. package/cjs/types/core/state.d.ts +80 -0
  12. package/cjs/types/features/addComment.d.ts +63 -0
  13. package/cjs/types/features/commentRenderer.d.ts +46 -0
  14. package/cjs/types/features/renderComments.d.ts +73 -0
  15. package/cjs/types/features/updateContent.d.ts +25 -0
  16. package/cjs/types/index.d.ts +14 -34
  17. package/cjs/types/types/common.d.ts +54 -0
  18. package/cjs/types/types/host.d.ts +65 -0
  19. package/cjs/types/types/state.d.ts +28 -0
  20. package/cjs/types/types/velt.d.ts +23 -0
  21. package/cjs/types/utils/common.d.ts +80 -0
  22. package/cjs/types/utils/console.d.ts +25 -0
  23. package/cjs/types/utils/serializer.d.ts +20 -0
  24. package/esm/index.js +1 -1
  25. package/esm/index.js.map +1 -1
  26. package/esm/types/adapters/host/doc.d.ts +86 -0
  27. package/esm/types/adapters/host/marks.d.ts +51 -0
  28. package/esm/types/adapters/host/storage.d.ts +38 -0
  29. package/esm/types/adapters/velt.d.ts +50 -0
  30. package/esm/types/constants/common.d.ts +58 -0
  31. package/esm/types/core/ExtensionComponent.d.ts +13 -0
  32. package/esm/types/core/extension.d.ts +54 -0
  33. package/esm/types/core/registry.d.ts +52 -0
  34. package/esm/types/core/state.d.ts +80 -0
  35. package/esm/types/features/addComment.d.ts +63 -0
  36. package/esm/types/features/commentRenderer.d.ts +46 -0
  37. package/esm/types/features/renderComments.d.ts +73 -0
  38. package/esm/types/features/updateContent.d.ts +25 -0
  39. package/esm/types/index.d.ts +14 -34
  40. package/esm/types/types/common.d.ts +54 -0
  41. package/esm/types/types/host.d.ts +65 -0
  42. package/esm/types/types/state.d.ts +28 -0
  43. package/esm/types/types/velt.d.ts +23 -0
  44. package/esm/types/utils/common.d.ts +80 -0
  45. package/esm/types/utils/console.d.ts +25 -0
  46. package/esm/types/utils/serializer.d.ts +20 -0
  47. package/index.d.ts +268 -34
  48. package/package.json +1 -1
  49. package/cjs/types/SlateVeltComment.d.ts +0 -6
  50. package/cjs/types/constants.d.ts +0 -9
  51. package/cjs/types/editor.d.ts +0 -72
  52. package/cjs/types/plugin.d.ts +0 -17
  53. package/cjs/types/store.d.ts +0 -36
  54. package/cjs/types/types.d.ts +0 -14
  55. package/cjs/types/velt.d.ts +0 -21
  56. package/esm/types/SlateVeltComment.d.ts +0 -6
  57. package/esm/types/constants.d.ts +0 -9
  58. package/esm/types/editor.d.ts +0 -72
  59. package/esm/types/plugin.d.ts +0 -17
  60. package/esm/types/store.d.ts +0 -36
  61. package/esm/types/types.d.ts +0 -14
  62. package/esm/types/velt.d.ts +0 -21
package/cjs/index.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";var t=require("slate"),e=require("slate-react"),o=require("react");function r(t,e,o,r){return new(o||(o=Promise))((function(n,i){function c(t){try{s(r.next(t))}catch(t){i(t)}}function a(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?n(t.value):(e=t.value,e instanceof o?e:new o((function(t){t(e)}))).then(c,a)}s((r=r.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const n={EDITOR_ID:"data-editor-id",LOCATION_ID:"data-velt-location-id"},i={VELT_COMMENT:"veltComment"};var c;class a{}c=a,a.selectedCommentsMap=new Map,a.subscribers=new Map,a.isSubscribed=!1,a.getCommentElement=()=>{try{const t=window.Velt;return(null==t?void 0:t.getCommentElement)?t.getCommentElement():null}catch(t){return c.catchError("Error getting comment element:",t),null}},a.addManualComment=({context:t,location:e})=>{try{const o=c.getCommentElement();return o?o.addManualComment({context:t,location:e}):Promise.resolve(null)}catch(t){return c.catchError("Error adding manual comment:",t),Promise.resolve(null)}},a.updateContext=({annotationId:t,context:e})=>{try{const o=c.getCommentElement();return o?o.updateContext(t,e):Promise.resolve(null)}catch(t){c.catchError("Error updating context:",t)}},a.subscribeToSelectedCommentsMap=(t,e)=>{try{c.subscribeToSelectedAnnotationsMapSingleton(),c.subscribers.set(t,e)}catch(t){c.catchError("Error subscribing to selected comments map:",t)}},a.unsubscribeFromSelectedCommentsMap=t=>{try{c.subscribers.delete(t)}catch(t){c.catchError("Error unsubscribing from selected comments map:",t)}},a.catchError=(t,e)=>{var o;try{let r={};e&&"object"==typeof e&&(r=Object.assign(Object.assign({},r),e)),t&&(r.message=t),r.sdkVersion=null===(o=window.Velt)||void 0===o?void 0:o.version}catch(t){}},a.subscribeToSelectedAnnotationsMapSingleton=()=>{var t;try{if(c.isSubscribed)return;const e=c.getCommentElement();e&&"function"==typeof(null==e?void 0:e.getSelectedComments)&&(null===(t=null==e?void 0:e.getSelectedComments())||void 0===t||t.subscribe((t=>{const e=new Map;null==t||t.forEach((t=>{(null==t?void 0:t.annotationId)&&e.set(null==t?void 0:t.annotationId,!0)}));((t,e)=>{if(t.size!==e.size)return!1;for(const[o,r]of t)if(e.get(o)!==r)return!1;return!0})(e,c.selectedCommentsMap||new Map)||c.updateSelectedCommentsMap(e)})),c.isSubscribed=!0)}catch(t){return new Map}},a.updateSelectedCommentsMap=t=>{try{c.selectedCommentsMap=t,c.subscribers.forEach((t=>{"function"==typeof t&&t(c.selectedCommentsMap)}))}catch(t){c.catchError("Error updating selected comments map:",t)}};class s{constructor(o){this.getSelectedText=e=>{try{return e.selection?t.Editor.string(e,e.selection):null}catch(t){return a.catchError("Error getting selected text:",t),null}},this.findOccurrenceOfText=t=>{try{const{searchText:e,scopeElement:o,startOffset:r=0,caseSensitive:n=!0}=t;if(!e)return{total:0,position:0};const i="string"==typeof o?o:(null==o?void 0:o.textContent)||"",c=n?t=>t:t=>t.toLowerCase(),a=c(i),s=c(e),l=[];let d=0;for(;;){const t=a.indexOf(s,d);if(-1===t)break;l.push(t),d=t+s.length}const u=l.filter((t=>t<r)).length+1;return{total:l.length,position:u}}catch(t){return a.catchError("Error finding occurrence of text:",t),null}},this.findOccurrenceOfSelectedText=(o,r)=>{var n;try{const i=this.getSelectedText(o);if(!i)return 0;if(!r){let e=0;const r=this.findAllMatches(o,i),n=o.selection;if(n){const o=t.Path.compare(n.anchor.path,n.focus.path)>0||t.Path.equals(n.anchor.path,n.focus.path)&&n.anchor.offset>n.focus.offset,i=r.findIndex((t=>o?t.anchor.path.toString()===n.focus.path.toString()&&t.focus.path.toString()===n.anchor.path.toString()&&t.anchor.offset===n.focus.offset&&t.focus.offset===n.anchor.offset:t.anchor.path.toString()===n.anchor.path.toString()&&t.focus.path.toString()===n.focus.path.toString()&&t.anchor.offset===n.anchor.offset&&t.focus.offset===n.focus.offset));-1!==i&&(e=i+1)}return e}const c=e.ReactEditor.toDOMNode(o,o),a=null===(n=o.selection)||void 0===n?void 0:n.anchor.offset,s=this.findOccurrenceOfText({searchText:i,scopeElement:r||c,startOffset:a});return null==s?void 0:s.position}catch(t){return a.catchError("Error finding occurrence of selected text:",t),null}},this.findAllMatches=(e,o,r={caseSensitive:!0})=>{try{const{caseSensitive:n=!0}=r,i=[];if(!o)return i;const c=t=>"object"==typeof t&&null!==t&&"text"in t?t.text:"",s=t=>"object"==typeof t&&null!==t&&"text"in t&&"string"==typeof t.text,l=(t,e)=>{if(s(t)){const r=c(t),a=n?o:o.toLowerCase(),s=n?r:r.toLowerCase();let l=0;for(;;){const t=s.indexOf(a,l);if(-1===t)break;const r={anchor:{path:e,offset:t},focus:{path:e,offset:t+o.length}};i.push(r),l=t+1}}"children"in t&&Array.isArray(t.children)&&t.children.forEach(((t,o)=>{l(t,[...e,o])}))};try{const[o]=t.Editor.nodes(e,{at:[],mode:"highest"});o&&l(o[0],o[1])}catch(t){a.catchError("Error searching in document:",t)}return i}catch(t){return a.catchError("Error finding all matches:",t),[]}},this.findParentNodeWithIdForSelection=e=>{try{const{selection:o}=e;if(!o)return null;const{anchor:r}=o,n=t.Node.get(e,r.path);return this.findParentNodeWithId(e,{node:n,path:r.path})}catch(t){return a.catchError("Error finding parent node with ID for selection:",t),null}},this.findParentNodeWithId=(o,r)=>{var n;try{let{node:i,path:c}=r||{};if(!i)return null;c&&(i=t.Editor.node(o,c)[0]);let a=null,s=null;try{a=e.ReactEditor.toDOMNode(o,i)}catch(t){return null}try{s=e.ReactEditor.toDOMNode(o,o)}catch(t){return null}const l=null!==(n=null==r?void 0:r.maxIterations)&&void 0!==n?n:100,d=null==r?void 0:r.idPattern;let u=a,h=0;for(;u&&u!==document.body&&h<l;){if(!s.contains(u))return null;if(u.id&&(!d||d.test(u.id)))return u;u=u.parentElement,h++}return null}catch(t){return a.catchError("Error finding parent node with ID:",t),null}},this.removeVeltCommentFromEditor=(o,r)=>{try{if(!o||!r)throw new Error("Invalid input: editor and annotationId are required");const n=[];for(const[e,i]of t.Node.descendants(o))s.isVeltCommentText(e)&&e.annotationId===r&&n.push(i);try{n.reverse().forEach((r=>{const n=t.Editor.node(o,r)[0],i=e.ReactEditor.toDOMNode(o,n);if(null==i?void 0:i.isConnected){const e=()=>{t.Transforms.unwrapNodes(o,{at:r,mode:"lowest"})},n=s.getHistoryEditor();n&&"function"==typeof n.withoutSaving?n.withoutSaving(o,(()=>{e()})):e()}}))}catch(t){a.catchError("Error unwrapping elements:",t)}return!0}catch(t){return a.catchError("Error removing Velt comment:",t),!1}},this.highlightTextWithVeltComment=(t,e)=>{var o;try{const{text:r,targetTextNodeId:n,occurrence:i}=(null===(o=null==e?void 0:e.context)||void 0===o?void 0:o.textEditorConfig)||{};if(!r||!i)return;this.injectTag(t,r,i,e.annotationId,n)&&e.annotationId&&this.plugin.storeService.annotationStore.set(e.annotationId,{annotation:e})}catch(t){a.catchError("Error highlighting text with velt comment:",t)}},this.getEditorTextContent=e=>{try{return e.children.map((e=>t.Node.string(e))).join("")}catch(t){return a.catchError("Error getting editor text content:",t),""}},this.onSlateValueChange=({editor:e})=>{try{const o=this.collectDocumentAnnotations({editor:e});if(0===o.size)return;const r=new Map;for(const[n]of o){if(!this.plugin.storeService.annotationStore.get(n))continue;if(!Array.from(t.Editor.nodes(e,{at:[]})).filter((([t])=>s.isVeltCommentText(t))).filter((([t])=>t.annotationId===n)).map((([o,r])=>({node:o,pos:t.Editor.start(e,r).offset}))).length)continue;const o=this.processAnnotationChanges({editor:e,annotationId:n});o&&r.set(n,o)}r.size>0&&this.updateVeltComments({changes:r,editor:e})}catch(t){a.catchError("Error in processVeltCommentChanges:",t)}},this.injectTag=(o,r,n,c,l)=>{try{let a=null;if(l){if(a=document.getElementById(l),!a)return!1;if(!this.isElementInEditor(o,a))return!1}else a=e.ReactEditor.toDOMNode(o,o);if(!a)return!1;const d=this.findTextOccurrence(o,r,n,a);if(!d)return!1;if(Array.from(t.Editor.nodes(o,{at:d,match:t=>s.isVeltCommentText(t)})).length>0)return!1;const u=()=>{o.wrapNodes({type:i.VELT_COMMENT,children:[],annotationId:c},{at:d,split:!0})},h=s.getHistoryEditor();return h&&"function"==typeof h.withoutSaving?h.withoutSaving(o,(()=>{u()})):u(),!0}catch(t){return a.catchError("Error injecting tag:",t),!1}},this.plugin=o}collectDocumentAnnotations({editor:e}){try{const o=new Map;return Array.from(t.Editor.nodes(e,{at:[]})).filter((([t])=>s.isVeltCommentText(t))).forEach((([t])=>{const e=t.annotationId;if(e){const t=this.plugin.storeService.annotationStore.get(e);(null==t?void 0:t.annotation)&&o.set(e,t.annotation)}})),o}catch(t){return a.catchError("Error collecting document annotations:",t),new Map}}processAnnotationChanges({editor:o,annotationId:r}){var n,i,c,l;try{let a=null,d=null,u=null;const h=null===(n=this.plugin.storeService.annotationStore.get(r))||void 0===n?void 0:n.annotation;if(!(null===(i=null==h?void 0:h.context)||void 0===i?void 0:i.textEditorConfig))return null;const{text:f,targetTextNodeId:g,occurrence:m}=(null===(c=null==h?void 0:h.context)||void 0===c?void 0:c.textEditorConfig)||{},E=Array.from(t.Editor.nodes(o,{at:[],match:t=>s.isVeltCommentText(t)&&t.annotationId===r,mode:"lowest"}));for(const[t,e]of E)a=t,u=e;if(!a)return null;try{if(d=e.ReactEditor.toDOMNode(o,a),!d)return null}catch(t){return null}const p=E.map((([e])=>t.Node.string(e))).join("");if(!p)return null;const v=this.findParentNodeWithId(o,{node:a,path:null!=u?u:void 0});let x,C,S;v&&(x=v.id),v&&(C=e.ReactEditor.toSlateNode(o,v),S=e.ReactEditor.findPath(o,C));const T=null===(l=this.findTextOccurrenceOfNode(o,a,null!=u?u:void 0,C,S))||void 0===l?void 0:l.nodeOccurrencePosition;if(!T)return null;const b=p!==f,y=T!==m,I=g!==x;return b||y||I?{contentChanged:b,currentText:p,occurrenceChanged:y,currentOccurrence:null!=T?T:0,originalOccurrence:m,annotationId:r,originalText:f,originalTargetTextNodeId:g,newTargetTextNodeId:x,annotation:h,multiThreadAnnotationId:null==h?void 0:h.multiThreadAnnotationId,targetTextNodeIdChanged:I}:null}catch(t){return a.catchError("Error processing annotation changes:",t),null}}updateVeltComments({changes:t,editor:e}){var o;try{for(const[r,n]of Array.from(t.entries()))try{if(!(null===(o=n.annotation.context)||void 0===o?void 0:o.textEditorConfig))continue;const t=JSON.parse(JSON.stringify(n.annotation.context.textEditorConfig));n.contentChanged&&(t.text=n.currentText),n.occurrenceChanged&&(t.occurrence=n.currentOccurrence),n.targetTextNodeIdChanged&&(t.targetTextNodeId=n.newTargetTextNodeId);const i=Object.assign(Object.assign({},n.annotation.context),{textEditorConfig:t});this.plugin.storeService.annotationStore.remove(r),this.removeVeltCommentFromEditor(e,r),a.updateContext({annotationId:r,context:i})}catch(t){a.catchError("Error updating Velt comments",t)}}catch(t){a.catchError("Error updating Velt comments",t)}}isElementInEditor(t,o){try{return e.ReactEditor.toDOMNode(t,t).contains(o)}catch(t){return a.catchError("Error checking element in editor:",t),!1}}traverseNodesForText(e,o,r,n){try{if(t.Text.isText(e)){const t=n.length,i=(n+=e.text).length;r.push({node:e,path:o,start:t,end:i})}else if(t.Element.isElement(e))for(let t=0;t<e.children.length;t++){const i=[...o,t];n=this.traverseNodesForText(e.children[t],i,r,n)}return n}catch(t){return a.catchError("Error traversing nodes for text:",t),""}}collectSubtreeText(t,e,o){try{const r=[];let n="";if(0===o.length)for(let e=0;e<t.children.length;e++){const o=[e];n=this.traverseNodesForText(t.children[e],o,r,n)}else n=this.traverseNodesForText(e,o,r,n);return{fullText:n,textNodePositions:r}}catch(t){return a.catchError("Error collecting subtree text:",t),{fullText:"",textNodePositions:[]}}}findTextOccurrence(t,o,r,n){try{const i=e.ReactEditor.toSlateNode(t,n),c=e.ReactEditor.findPath(t,i),{fullText:a,textNodePositions:s}=this.collectSubtreeText(t,i,c),l=[];let d;const u=new RegExp(o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"g");for(;null!==(d=u.exec(a));)l.push({index:d.index});if(l.length<r)return null;const h=l[r-1].index,f=h+o.length;let g,m;for(const t of s)if(h>=t.start&&h<t.end&&(g=t),f>t.start&&f<=t.end&&(m=t),g&&m)return{anchor:{path:g.path,offset:h-g.start},focus:{path:m.path,offset:f-m.start}};return null}catch(t){return a.catchError("Error in findTextOccurrence:",t),null}}findAllTextOccurrences(e,o,r=!0,n,i){try{if(!o)return[];const c=[],s=r?t=>t:t=>t.toLowerCase(),l=s(o);if(n&&!i)try{for(const[o,r]of t.Editor.nodes(e))if(o===n){i=r;break}}catch(t){a.catchError("Error finding container path:",t)}const d=i||[];for(const[r,n]of t.Editor.nodes(e,{at:d,match:e=>t.Text.isText(e)})){if(i&&!t.Path.isDescendant(n,i)&&!t.Path.equals(n,i))continue;const e=t.Node.string(r),a=s(e);let d,u=0;for(;-1!==(d=a.indexOf(l,u));){const t={path:n,offset:d},i={path:n,offset:d+o.length},a={anchor:t,focus:i};c.push({node:r,path:n,range:a,startPoint:t,endPoint:i,text:e.substring(d,d+o.length)}),u=d+l.length}}return c}catch(t){return a.catchError("Error finding all text occurrences:",t),[]}}findTextOccurrenceOfNode(o,r,n,i,c){try{const s=t.Node.string(r);if(!s.trim())return{node:r,nodePath:n,text:s,totalOccurrences:0,nodeOccurrencePosition:0,textOccurrences:[],containerNode:i,containerPath:c};if(!n)try{if("findPath"in e.ReactEditor)try{n=e.ReactEditor.findPath(o,r)}catch(t){a.catchError("Error finding path with ReactEditor:",t)}if(!n)for(const[e,i]of t.Editor.nodes(o))if(e===r){n=i;break}}catch(t){a.catchError("Error finding node path:",t)}const l=this.findAllTextOccurrences(o,s,!0,i,c);let d=0;if(n)for(let e=0;e<l.length;e++){const o=l[e],r=t.Path.equals(o.path,n),i=t.Path.isAncestor(n,o.path);if(r||i){d=e+1;break}}return{node:r,nodePath:n,text:s,totalOccurrences:l.length,nodeOccurrencePosition:d,textOccurrences:l,containerNode:i,containerPath:c}}catch(t){return a.catchError("Error finding text occurrence of node:",t),null}}}s.setHistoryEditor=t=>{s.HistoryEditor=t},s.getHistoryEditor=()=>s.HistoryEditor,s.getEditorId=t=>{var o,r;try{const i=e.ReactEditor.toDOMNode(t,t);return i&&(null!==(r=null===(o=null==i?void 0:i.closest(`[${n.EDITOR_ID}]`))||void 0===o?void 0:o.getAttribute(n.EDITOR_ID))&&void 0!==r)?r:null}catch(t){return a.catchError("Error finding editor ID:",t),null}},s.isVeltCommentText=t=>t.type===i.VELT_COMMENT;class l{constructor(t){this.isSubscribed=!1,this.globalStore={editor:null,comments:[],filteredComments:[],selectedCommentsMap:new Map},this.globalAnnotationStore=new Map,this.annotationStore={get:t=>this.globalAnnotationStore.get(t),set:(t,e)=>{this.globalAnnotationStore.set(t,e)},getAll:()=>new Map(this.globalAnnotationStore),clear:()=>{this.globalAnnotationStore.clear()},remove:t=>{this.globalAnnotationStore.delete(t)}},this.updateGlobalStore=t=>{var e,o,r;try{const n=(null==t?void 0:t.comments)||(null===(e=this.globalStore)||void 0===e?void 0:e.comments)||[],i=(null==t?void 0:t.selectedCommentsMap)||(null===(o=this.globalStore)||void 0===o?void 0:o.selectedCommentsMap)||new Map,c=(null===(r=this.globalStore)||void 0===r?void 0:r.filteredComments)||[],a=n.filter((t=>{var e;return"terminal"!==(null===(e=null==t?void 0:t.status)||void 0===e?void 0:e.type)||(null==i?void 0:i.get(null==t?void 0:t.annotationId))})),s=new Set(a.map((t=>null==t?void 0:t.annotationId)));c.map((t=>null==t?void 0:t.annotationId)).filter((t=>t&&!s.has(t))).forEach((t=>{var e,o;(null===(e=this.globalStore)||void 0===e?void 0:e.editor)&&t&&this.plugin.editorService.removeVeltCommentFromEditor(null===(o=this.globalStore)||void 0===o?void 0:o.editor,t)})),this.globalStore=Object.assign(Object.assign(Object.assign({},this.globalStore),t),{filteredComments:a}),this.highlightCommentsFromGlobalStore()}catch(t){a.catchError("Error updating global store:",t)}},this.highlightCommentsFromGlobalStore=()=>{var t,e;try{const{editor:o,filteredComments:r}=this.globalStore;if(!o||!r)return;for(const n of r){(null===(e=null===(t=null==n?void 0:n.context)||void 0===t?void 0:t.textEditorConfig)||void 0===e?void 0:e.text)&&this.plugin.editorService.highlightTextWithVeltComment(o,n)}}catch(t){a.catchError("Error highlighting comments from global store:",t)}},this.plugin=t;try{a.subscribeToSelectedCommentsMap(this.plugin.editorId,(t=>{try{this.updateGlobalStore({selectedCommentsMap:t})}catch(t){a.catchError("Error updating global store:",t)}}))}catch(t){a.catchError("Error subscribing to selected comments map:",t)}}}l.storeInstanceMap=new Map;const d=new Map;class u{constructor(t,e){this.previousEditorTextContent="",this.editorId=t,this.editor=e,this.editorService=new s(this),this.storeService=new l(this),e&&this.setPreviousEditorTextContent(this.editorService.getEditorTextContent(e))}static getInstance(t){let{editorId:e,editor:o}=t||{};return e||(e="default"),d.has(e)||d.set(e,new u(e,o)),d.get(e)}getPreviousEditorTextContent(){return this.previousEditorTextContent}setPreviousEditorTextContent(t){this.previousEditorTextContent=t}}const h=t=>r(void 0,[t],void 0,(function*({editorId:t,editor:e,context:o}){var r,n;try{if(!a.getCommentElement())return;t||(t=null!==(r=s.getEditorId(e))&&void 0!==r?r:void 0);const i=u.getInstance({editorId:t,editor:e}),c=i.editorService.getSelectedText(e);if(!c)return;const l=i.editorService.findParentNodeWithIdForSelection(e);let d,h=null;l&&(d=l.id,h=null===(n=l.closest("[data-velt-location-id]"))||void 0===n?void 0:n.getAttribute("data-velt-location-id"));const f=i.editorService.findOccurrenceOfSelectedText(e,null!=l?l:void 0);if(!f)return;let g,m={};o&&"object"==typeof o&&(m=Object.assign(Object.assign({},m),o)),m.textEditorConfig={text:c,occurrence:f,targetTextNodeId:d},t&&(m.textEditorConfig.editorId=t),yield new Promise((t=>setTimeout(t,200))),h&&(g={id:h});try{a.addManualComment({context:m,location:g})}catch(t){a.catchError("Error creating comment",t)}}catch(t){a.catchError("Error adding comment",t)}}));const f=({editor:t,editorId:e,commentAnnotations:o})=>{var r;try{if(t){e||(e=null!==(r=s.getEditorId(t))&&void 0!==r?r:void 0),o=null==o?void 0:o.filter((t=>{var o,r,n;return!!(null===(o=t.context)||void 0===o?void 0:o.textEditorConfig)&&(null===(n=null===(r=t.context)||void 0===r?void 0:r.textEditorConfig)||void 0===n?void 0:n.editorId)===e}));u.getInstance({editorId:e,editor:t}).storeService.updateGlobalStore({editor:t,comments:o}),a.subscribeToSelectedAnnotationsMapSingleton()}}catch(t){a.catchError("Error highlighting tiptap-velt-comments",t)}},g=({editor:t,editorId:e})=>{var o;try{e||(e=null!==(o=s.getEditorId(t))&&void 0!==o?o:void 0);const r=u.getInstance({editorId:e,editor:t}),n=r.editorService.getEditorTextContent(t);if(n===r.getPreviousEditorTextContent())return;r.setPreviousEditorTextContent(n),r.editorService.onSlateValueChange({editor:t})}catch(t){a.catchError("Error in processVeltCommentChanges:",t)}};exports.SlateVeltComment=t=>{const{attributes:e,children:r,element:n}=t,i=null==n?void 0:n.annotationId;return o.createElement("velt-comment-text",Object.assign({"annotation-id":i},e),r)},exports.addComment=h,exports.highlightComments=function(t,e,o){try{f({editor:t,editorId:o,commentAnnotations:e})}catch(t){a.catchError("Error highlighting tiptap-velt-comments",t)}},exports.onSlateValueChange=g,exports.renderComments=f,exports.triggerAddComment=(t,e)=>r(void 0,void 0,void 0,(function*(){try{return h({editor:t,context:null==e?void 0:e.context})}catch(t){a.catchError("Error triggering add comment",t)}})),exports.withVeltComments=(e,o)=>{const{isInline:r,isVoid:n,onChange:i}=e;return(null==o?void 0:o.HistoryEditor)&&s.setHistoryEditor(o.HistoryEditor),e.isInline=t=>!!s.isVeltCommentText(t)||r(t),e.isVoid=t=>!s.isVeltCommentText(t)&&n(t),e.onChange=()=>{i&&i();e.operations.some((e=>t.Operation.isTextOperation(e)))&&g({editor:e})},e};
1
+ "use strict";var t=require("slate"),n=require("slate-react"),e=require("react");const o={EDITOR_ID:"data-editor-id",LOCATION_ID:"data-velt-location-id",ANNOTATION_ID:"annotation-id",MULTI_THREAD_ANNOTATION_ID:"multi-thread-annotation-id"},r={VELT_COMMENT:"veltComment"},c="veltComment",i="slateVeltComments",a="__default__",s="terminal",d="SlateVeltComments: ",l="debugMode",u="forceDebugMode",f=(t,n,e=0,o)=>{const r=[];if(!n||!t||n.length>t.length)return r;const c=(t=>{if(!t||0===t.length)return[];const n=new Array(t.length).fill(0);let e=0,o=1;for(;o<t.length;)t[o]===t[e]?(e++,n[o]=e,o++):0!==e?e=n[e-1]:(n[o]=0,o++);return n})(n);let i=0,a=0;for(;i<t.length;)if(n[a]===t[i]&&(i++,a++),a===n.length){if(r.push(e+i-a),a=c[a-1],o&&r.length>=o)break}else i<t.length&&n[a]!==t[i]&&(0!==a?a=c[a-1]:i++);return r};class h{static showLogs(){try{return!!sessionStorage.getItem(l)||!!sessionStorage.getItem(u)}catch(t){return h.catch("Error in showLogs: ",t),!1}}}h.log=h.showLogs()?console.log:()=>{},h.warn=h.showLogs()?console.warn:()=>{},h.error=h.showLogs()?console.error:()=>{},h.debug=h.showLogs()?console.debug:()=>{},h.info=h.showLogs()?console.info:()=>{},h.logsEnabled=!0,h.catch=(t,n)=>{try{h.logsEnabled&&(void 0!==n?console.warn(d,t,n):console.warn(d,t))}catch(t){}};const g=t=>{var e,r;try{const c=n.ReactEditor.toDOMNode(t,t);return c&&(null!==(r=null===(e=null==c?void 0:c.closest(`[${o.EDITOR_ID}]`))||void 0===e?void 0:e.getAttribute(o.EDITOR_ID))&&void 0!==r)?r:null}catch(t){return null}},p=(n,e,o)=>{try{if(!e||!n.selection)return 0;if(o){const t=document.getElementById(o);if(t){const o=n.selection.anchor.offset;return y(t,e,o)}}const r=x(n,e),c=n.selection;if(!c||0===r.length)return 0;const i=t.Path.compare(c.anchor.path,c.focus.path)>0||t.Path.equals(c.anchor.path,c.focus.path)&&c.anchor.offset>c.focus.offset,a=r.findIndex((n=>i?t.Path.equals(n.anchor.path,c.focus.path)&&t.Path.equals(n.focus.path,c.anchor.path)&&n.anchor.offset===c.focus.offset&&n.focus.offset===c.anchor.offset:t.Path.equals(n.anchor.path,c.anchor.path)&&t.Path.equals(n.focus.path,c.focus.path)&&n.anchor.offset===c.anchor.offset&&n.focus.offset===c.focus.offset));return-1!==a?a+1:0}catch(t){return h.catch("[HostAdapter] Error finding occurrence index:",t),0}},m=n=>{try{const{selection:e}=n;if(!e)return null;const{anchor:o}=e,r=t.Node.get(n,o.path);return E(n,r,o.path)}catch(t){return h.catch("[HostAdapter] Error finding parent node with ID:",t),null}},E=(t,e,o,r=100)=>{try{let o=null,c=null;try{o=n.ReactEditor.toDOMNode(t,e)}catch(t){return null}try{c=n.ReactEditor.toDOMNode(t,t)}catch(t){return null}let i=o,a=0;for(;i&&i!==document.body&&a<r;){if(!c.contains(i))return null;if(i.id)return i;i=i.parentElement,a++}return null}catch(t){return h.catch("[HostAdapter] Error finding parent node:",t),null}},v=(e,o,r,c,i)=>{try{if(!o)return 0;const a=t.Node.string(r);if(!a||!a.trim())return 0;let s,d;if(i){const t=document.getElementById(i);if(t)try{s=n.ReactEditor.toSlateNode(e,t),d=n.ReactEditor.findPath(e,s)}catch(t){h.warn("[findOccurrenceForNode] Could not find container node:",t)}}const l=x(e,o);if(0===l.length)return 0;let u=l;if(d&&(u=l.filter((n=>{const o=t.Editor.start(e,n);return t.Path.isAncestor(d,o.path)||t.Path.equals(d,o.path)}))),0===u.length)return 0;for(let n=0;n<u.length;n++){const o=u[n],r=t.Editor.start(e,o).path,i=t.Path.equals(r,c),a=t.Path.isAncestor(c,r);if(i||a){const t=l.indexOf(o);return-1!==t?t+1:n+1}}return h.warn("[findOccurrenceForNode] No matching occurrence found for text:",o,"node path:",c),0}catch(t){return h.catch("[HostAdapter] Error finding occurrence for node:",t),0}},x=(n,e,o=!0)=>{try{const r=[];if(!e)return r;const c=t=>"object"==typeof t&&null!==t&&"text"in t?t.text:"",i=t=>"object"==typeof t&&null!==t&&"text"in t&&"string"==typeof t.text,a=(t,n)=>{if(i(t)){const i=c(t),a=o?e:e.toLowerCase(),s=o?i:i.toLowerCase(),d=f(s,a);for(const t of d){const o={anchor:{path:n,offset:t},focus:{path:n,offset:t+e.length}};r.push(o)}}"children"in t&&Array.isArray(t.children)&&t.children.forEach(((t,e)=>{a(t,[...n,e])}))};try{const[e]=t.Editor.nodes(n,{at:[],mode:"highest"});e&&a(e[0],e[1])}catch(t){h.catch("[HostAdapter] Error searching in document:",t)}return r}catch(t){return h.catch("[HostAdapter] Error finding all matches:",t),[]}},y=(t,n,e,o=!0)=>{try{if(!n)return 0;const r=t.textContent||"",c=o?r:r.toLowerCase(),i=o?n:n.toLowerCase(),a=f(c,i);if(0===a.length)return 0;if(void 0!==e){return a.filter((t=>t<e)).length+1}return 1}catch(t){return h.catch("[HostAdapter] Error finding occurrence in DOM:",t),0}},I=(t,n)=>{try{let e=t;return e||(e=g(n)||"default"),{editorId:e}}catch(n){return h.warn("[ensureEditorSetup] Error setting up editor:",n),{editorId:t||"default"}}};let w=null;const N=n=>t.Element.isElement(n)&&n.type===r.VELT_COMMENT,T=(e,o,c,i,a,s)=>{const d="[applyAnnotationMarkByText]";try{if(!e||!i)return!1;const l=e;let u=null;if(s){if(u=document.getElementById(s),!u)return h.warn(`${d} Target element not found: ${s}`),!1;if(!O(l,u))return h.warn(`${d} Target element not in editor: ${s}`),!1}else u=n.ReactEditor.toDOMNode(l,l);if(!u)return h.warn(`${d} No target element found`),!1;const f=C(l,o,c,u);return f?((n,e,o,c)=>{try{if(!c)return!1;if(Array.from(t.Editor.nodes(n,{at:c,match:n=>!!t.Element.isElement(n)&&N(n)})).length>0)return!1;const i=()=>{t.Transforms.wrapNodes(n,{type:r.VELT_COMMENT,children:[],annotationId:e,multiThreadAnnotationId:o},{at:c,split:!0})};return w&&"function"==typeof w.withoutSaving?w.withoutSaving(n,(()=>{i()})):i(),!0}catch(t){return h.catch("[HostAdapter] Error applying annotation mark:",t),!1}})(l,i,a,f):(h.warn(`${d} Could not find text occurrence range for "${o}" occurrence ${c}`),!1)}catch(t){return h.catch(`${d} Error applying annotation mark by text:`,t),!1}},A=(e,o)=>{try{if(!e||!o)return!1;const r=[];for(const[n,c]of t.Node.descendants(e))t.Element.isElement(n)&&N(n)&&n.annotationId===o&&r.push(c);try{r.reverse().forEach((o=>{const r=t.Node.get(e,o),c=n.ReactEditor.toDOMNode(e,r);if(null==c?void 0:c.isConnected){const n=()=>{t.Transforms.unwrapNodes(e,{at:o,mode:"lowest"})};w&&"function"==typeof w.withoutSaving?w.withoutSaving(e,(()=>{n()})):n()}}))}catch(t){h.catch("[HostAdapter] Error unwrapping elements:",t)}return!0}catch(t){return h.catch("[HostAdapter] Error removing annotation mark:",t),!1}},O=(t,e)=>{try{return n.ReactEditor.toDOMNode(t,t).contains(e)}catch(t){return h.catch("[HostAdapter] Error checking element in editor:",t),!1}},C=(t,e,o,r)=>{const c="[findTextOccurrenceRange]";try{const i=n.ReactEditor.toSlateNode(t,r);if(!i)return h.warn(`${c} Could not convert target element to Slate node`),null;const a=n.ReactEditor.findPath(t,i),{fullText:s,textNodePositions:d}=b(t,i,a),l=[];let u;const f=new RegExp(e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),"g");for(;null!==(u=f.exec(s));)l.push({index:u.index});if(l.length<o)return h.warn(`${c} Not enough occurrences: found ${l.length}, need ${o}`),null;const g=l[o-1].index,p=g+e.length;let m,E;for(const t of d)if(g>=t.start&&g<t.end&&!m&&(m=t),p>t.start&&p<=t.end&&!E&&(E=t),m&&E){return{anchor:{path:m.path,offset:g-m.start},focus:{path:E.path,offset:p-E.start}}}return h.warn(`${c} Could not find anchor/focus nodes for match`),null}catch(t){return h.catch(`${c} Error finding text occurrence range:`,t),null}},b=(n,e,o)=>{const r=[];let c="";const i=(n,e,o,r)=>{try{if(t.Text.isText(n)){const t=r.length,c=(r+=n.text).length;o.push({node:n,path:e,start:t,end:c})}else if(t.Element.isElement(n))for(let t=0;t<n.children.length;t++){const c=[...e,t];r=i(n.children[t],c,o,r)}return r}catch(t){return h.catch("[HostAdapter] Error traversing nodes for text:",t),r}};if(0===o.length)for(let t=0;t<n.children.length;t++){const e=[t];c=i(n.children[t],e,r,c)}else c=i(e,o,r,c);return{fullText:c,textNodePositions:r}},M=new Map,$=t=>{const n={annotations:new Map,commentAnnotations:[],selectedAnnotations:new Set,editorId:t};return M.set(t,n),n},S=t=>{let n=M.get(t);return n||(n=$(t)),n},V=(t,n)=>{try{const e=S(t);e.commentAnnotations=n;const o=new Map;for(const t of n){if(!(null==t?void 0:t.annotationId))continue;const n={annotationId:t.annotationId,multiThreadAnnotationId:t.multiThreadAnnotationId,context:t.context};o.set(t.annotationId,n)}e.annotations=o}catch(t){h.catch("Error updating annotations:",t)}},k=(t,n)=>{try{const e=M.get(t);return e&&e.annotations.get(n)||null}catch(t){return h.catch("Error getting annotation:",t),null}},D=new Map;function L(t,n,e,o){return new(e||(e=Promise))((function(r,c){function i(t){try{s(o.next(t))}catch(t){c(t)}}function a(t){try{s(o.throw(t))}catch(t){c(t)}}function s(t){var n;t.done?r(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(i,a)}s((o=o.apply(t,n||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;let R=!1,_=new Map;const H=new Map,P=()=>{try{const t=window.Velt;return(null==t?void 0:t.getCommentElement)?t.getCommentElement():null}catch(t){return h.catch("[VeltAdapter] Error getting comment element:",t),null}},j=(t,n)=>{try{const e=P();if(!e)return;e.updateContext(t,n)}catch(t){h.catch("[VeltAdapter] Error updating context:",t)}},q=()=>{const t=P();if(!(null==t?void 0:t.getSelectedComments))return!1;try{const n=t.getSelectedComments();if(!(null==n?void 0:n.subscribe))return!1;const e=n.subscribe((t=>{const n=new Map;if(null==t||t.forEach((t=>{(null==t?void 0:t.annotationId)&&n.set(t.annotationId,!0)})),!((t,n)=>{if(t.size!==n.size)return!1;for(const[e,o]of Array.from(t))if(n.get(e)!==o)return!1;return!0})(n,_)){_=n;const t=new Set;for(const[e]of n)t.add(e);H.forEach((n=>{if("function"==typeof n)try{n(t)}catch(t){h.catch("[VeltAdapter] Error in subscriber callback:",t)}}))}}));if(e&&"function"==typeof e.unsubscribe)return R=!0,!0}catch(t){h.catch("[VeltAdapter] Error setting up getSelectedComments subscription:",t)}return!1},B=(n,e,o)=>{var i;const a="[handleContentUpdate]";try{const o=t=>{var e,o,r,c,i,s;const d=k(n,t);if(!d)return h.warn(`${a} Annotation not found in state: ${t}`),null;return{annotation:d,originalText:(null===(o=null===(e=d.context)||void 0===e?void 0:e.textEditorConfig)||void 0===o?void 0:o.text)||"",originalOccurrence:(null===(c=null===(r=d.context)||void 0===r?void 0:r.textEditorConfig)||void 0===c?void 0:c.occurrence)||1,targetTextNodeId:(null===(s=null===(i=d.context)||void 0===i?void 0:i.textEditorConfig)||void 0===s?void 0:s.targetTextNodeId)||""}},s=((n,e,o=c,i)=>{const a="[detectDocumentChanges]",s=new Map;try{const e=Array.from(t.Editor.nodes(n,{at:[],match:n=>t.Element.isElement(n)&&n.type===r.VELT_COMMENT&&"annotationId"in n,mode:"lowest"}));for(const[o,r]of e){const e=o.annotationId;if(!e){h.warn(`${a} Node missing annotationId, skipping`);continue}const c=i(e);if(!c){h.warn(`${a} No stored data found for annotationId: ${e}, skipping`);continue}const d=c.originalText,l=c.originalOccurrence,u=c.targetTextNodeId||"",f=t.Node.string(o);if(!f){h.warn(`${a} Node has no text content, skipping`);continue}const g=E(n,o,r),p=(null==g?void 0:g.id)||"",m=v(n,f,o,r,p),x=f!==d,y=m!==l,I=u!==p;if(x||y||I){const t=c.annotation;s.set(e,{annotationId:e,multiThreadAnnotationId:t.multiThreadAnnotationId,originalText:d,currentText:f,originalOccurrence:l,currentOccurrence:m,originalTargetTextNodeId:u,newTargetTextNodeId:p,annotation:t,contentChanged:x,occurrenceChanged:y,targetTextNodeIdChanged:I})}}}catch(t){h.catch("[HostAdapter] Error detecting document changes:",t)}return s})(e,0,c,o);if(0===s.size)return;for(const[t,e]of Array.from(s.entries())){const o=`${a}[${t}]`,r=k(n,t);if(!r){h.warn(`${o} Annotation not found in state, skipping`);continue}if(!(null===(i=r.context)||void 0===i?void 0:i.textEditorConfig)){h.warn(`${o} No textEditorConfig, skipping`);continue}const c=JSON.parse(JSON.stringify(r.context.textEditorConfig));e.contentChanged&&(c.text=e.currentText),e.occurrenceChanged&&(c.occurrence=e.currentOccurrence),e.targetTextNodeIdChanged&&(c.targetTextNodeId=e.newTargetTextNodeId);const s=Object.assign(Object.assign({},r.context),{textEditorConfig:c});j(t,s)}((t,n)=>{try{for(const[e,o]of n)A(t,e)}catch(t){h.catch("[HostAdapter] Error updating marks:",t)}})(e,s)}catch(t){h.catch("Error handling content update:",t)}},F=n=>t.Element.isElement(n)&&n.type===r.VELT_COMMENT,J=(t,n=i)=>{var e;try{const n=g(t);if(!n)return!0;const o=(t=>D.get(t)||null)(n);return void 0===(null===(e=null==o?void 0:o.config)||void 0===e?void 0:e.persistVeltMarks)||o.config.persistVeltMarks}catch(t){return h.warn("[getPersistVeltMarks] Error checking persistVeltMarks, defaulting to true:",t),!0}};const z=new Map,K=(t,n,e)=>{var o;try{const r=z.get(t);r?r.editor=n:z.set(t,{editor:n,previousFilteredAnnotations:[]});const c=(t=>{try{const n=M.get(t);return n?new Set(n.selectedAnnotations):new Set}catch(t){return h.catch("Error getting selected annotations:",t),new Set}})(t),i=((t,n)=>t.filter((t=>{var e;return(null===(e=null==t?void 0:t.status)||void 0===e?void 0:e.type)!==s||n.has(t.annotationId)})))(e,c),a=(null===(o=z.get(t))||void 0===o?void 0:o.previousFilteredAnnotations)||[],d=new Set(i.map((t=>t.annotationId)).filter(Boolean)),l=new Set(a.map((t=>t.annotationId)).filter(Boolean)),u=Array.from(l).filter((t=>!d.has(t)));for(const t of u)t&&A(n,t);const f=z.get(t);f&&(f.previousFilteredAnnotations=i),((t,n)=>{var e;for(const o of n){const n=null===(e=null==o?void 0:o.context)||void 0===e?void 0:e.textEditorConfig;if(!(null==n?void 0:n.text)||!o.annotationId)continue;const r=n.text,c=n.occurrence||1,i=n.targetTextNodeId;T(t,r,c,o.annotationId,o.multiThreadAnnotationId,i)}})(n,i)}catch(t){h.catch("[commentRenderer:updateComments] Error updating comments:",t)}},U=(t,n)=>{const e="[commentRenderer:updateSelection]";try{const n=z.get(t);if(!n||!n.editor)return void h.warn(`${e} No editor found for editorId: ${t}`);const o=(t=>{try{const n=M.get(t);return n?[...n.commentAnnotations]:[]}catch(t){return h.catch("Error getting comment annotations:",t),[]}})(t);K(t,n.editor,o)}catch(t){h.catch(`${e} Error updating selection:`,t)}},W=new Map,G=r.VELT_COMMENT,Q=t=>X(t),X=t=>{const n=[];for(const e of t)if(et(e)&&e.type===G){const t=X(e.children);n.push(...t)}else n.push(Y(e));return n},Y=t=>{if(et(t)){const n=X(t.children);return Object.assign(Object.assign({},t),{children:n})}return t},Z=t=>{const n=t.map(tt);return nt(n)},tt=t=>{if(et(t)){const n=t.children.map(tt);return Object.assign(Object.assign({},t),{children:nt(n)})}return t},nt=t=>{var n,e;if(t.length<2)return t;const o=[];let r=0;for(;r<t.length;){const c=t[r];if(ot(c)){if(""===c.text){r++;continue}let i=null!==(n=c.text)&&void 0!==n?n:"",a=r+1;for(;a<t.length;){const n=t[a];if(ot(n)&&""===n.text)a++;else{if(!ot(n)||!rt(c,n))break;i+=null!==(e=n.text)&&void 0!==e?e:"",a++}}o.push(Object.assign(Object.assign({},c),{text:i})),r=a}else o.push(c),r++}return o.length>0?o:[{text:""}]},et=t=>Object.prototype.hasOwnProperty.call(t,"children")&&Object.prototype.hasOwnProperty.call(t,"type"),ot=t=>Object.prototype.hasOwnProperty.call(t,"text"),rt=(t,n)=>t.bold===n.bold&&t.italic===n.italic&&t.underline===n.underline;exports.SlateVeltComment=t=>{const{attributes:n,children:r,element:c}=t,i=null==c?void 0:c.annotationId;return e.createElement("velt-comment-text",Object.assign({[o.ANNOTATION_ID]:i},n),r)},exports.addComment=function(n){return L(this,arguments,void 0,(function*({editorId:n,editor:e,context:r}){const c="[addComment]";var s;if(e)try{if(!P())return void h.warn(`${c} Velt SDK not available, cannot add comment`);const d=(n=>{var e;try{if(!n.selection)return null;const r=t.Editor.string(n,n.selection);if(!r)return null;const c=t.Editor.start(n,n.selection).offset,i=t.Editor.end(n,n.selection).offset,a=m(n),s=null==a?void 0:a.id;let d;return a&&(d=(null===(e=a.closest(`[${o.LOCATION_ID}]`))||void 0===e?void 0:e.getAttribute(o.LOCATION_ID))||void 0),{text:r,from:c,to:i,occurrence:p(n,r,s),targetTextNodeId:s,locationId:d}}catch(t){return h.catch("[HostAdapter] Error getting selection context:",t),null}})(e);if(!d)return void h.warn(`${c} No valid selection found, exiting`);const{editorId:l}=I(n,e),u=void 0!==n||l!==a,f=Object.assign(Object.assign({},r&&"object"==typeof r?r:{}),{textEditorConfig:Object.assign(Object.assign({text:d.text,occurrence:d.occurrence},u&&{editorId:l}),{targetTextNodeId:d.targetTextNodeId})});let g;d.locationId&&(g={id:d.locationId}),yield new Promise((t=>setTimeout(t,200)));const E=yield(s={context:f,location:g},L(void 0,void 0,void 0,(function*(){try{const t=P();if(!t)return null;const n=yield t.addManualComment({context:s.context,location:s.location});return n?{annotation:n}:null}catch(t){return h.catch("[VeltAdapter] Error adding comment:",t),null}})));if(!E||!E.annotation)return void h.warn(`${c} Failed to create comment via Velt SDK`);const v=E.annotation,x=((t,n=i)=>{try{return!1===J(t,n)}catch(t){return h.warn("[shouldApplyMark] Error checking persistVeltMarks, defaulting to true:",t),!0}})(e,i);x&&v.annotationId&&T(e,d.text,d.occurrence,v.annotationId,v.multiThreadAnnotationId,d.targetTextNodeId),v.annotationId?V(l,[v]):h.warn(`${c} No annotationId, skipping state update`)}catch(t){h.catch(`${c} Error adding comment:`,t)}else h.catch(`${c} ERROR: No editor provided`)}))},exports.exportJSONWithoutComments=t=>{const n=Q(t);return Z(n)},exports.renderComments=({editor:t,editorId:n,commentAnnotations:e})=>{const o="[renderComments]";try{if(!t)return void h.warn(`${o} No editor provided`);e&&Array.isArray(e)||(e=[]);const{editorId:r}=I(n,t),c=JSON.parse(JSON.stringify(e)).filter((t=>{var n;if(!(null===(n=null==t?void 0:t.context)||void 0===n?void 0:n.textEditorConfig))return!1;const e=t.context.textEditorConfig.editorId;return r===a?void 0===e||e===a:e===r}));if(V(r,c),!W.has(r)){const t=r,n=((t,n)=>{try{return H.set(n,t),R||q(),()=>{H.delete(n)}}catch(t){return h.catch("[VeltAdapter] Error subscribing to selected annotations:",t),()=>{}}})((n=>{((t,n)=>{try{S(t).selectedAnnotations=new Set(n)}catch(t){h.catch("Error setting selected annotations:",t)}})(t,n),U(t)}),t);W.set(r,n)}R||q(),K(r,t,c)}catch(t){h.catch(`${o} Error rendering comments:`,t)}},exports.withVeltComments=(n,e)=>{var o;const{isInline:r,isVoid:c,onChange:i}=n;var a;(null==e?void 0:e.HistoryEditor)&&(a=e.HistoryEditor,w=a);const s=(null==e?void 0:e.editorId)||g(n)||"default";return((t,n,e)=>{const o=t||"default";$(o);const r={editorId:o,editor:n,config:e||{}};D.set(o,r)})(s,n,{persistVeltMarks:null===(o=null==e?void 0:e.persistVeltMarks)||void 0===o||o,editorId:s,HistoryEditor:null==e?void 0:e.HistoryEditor}),n.isInline=t=>!!F(t)||r(t),n.isVoid=t=>!F(t)&&c(t),n.onChange=()=>{i&&i();n.operations.some((n=>t.Operation.isTextOperation(n)))&&B(s,n)},n};
2
2
  //# sourceMappingURL=index.js.map