@veltdev/sdk
Version:
Velt is an SDK to add collaborative features to your product within minutes. Example: Comments like Figma, Frame.io, Google docs or sheets, Recording like Loom, Huddles like Slack and much more.
1 lines • 5.96 MB
JavaScript
import{C as Gu}from"./chunk-GJJML4YW.js";import{a as zb}from"./chunk-RZ4WYBKV.js";import{a as Jb}from"./chunk-T5PFG7WD.js";import{a as Ah,b as Ph,c as Lg,d as Bg}from"./chunk-FX3FOBZV.js";import{a as Vg}from"./chunk-RRHXMXZH.js";import"./chunk-JP3HOBZL.js";import"./chunk-FHPKMTSO.js";import{b as wh,c as Ih,d as Dh}from"./chunk-KEET32BV.js";import{a as Yr}from"./chunk-HUCTUED7.js";import{b as Wb}from"./chunk-ICCKJPGL.js";import{a as pg,c as Vh,d as $h}from"./chunk-BDHZZGJO.js";import{a as hn}from"./chunk-BWEYL3QS.js";import{a as no}from"./chunk-6YXU2Y3T.js";import{a as yb,b as ro,c as Nb,d as Pg,e as Rb,f as Ub,g as Cr,h as Fg,i as Lb,j as Ng,k as pn,n as Rg,o as Bb,p as Vb,q as $v,r as $b,s as Gb,t as jb}from"./chunk-BACKCNIG.js";import"./chunk-JFNRCHYR.js";import{b as sg,c as gg,g as ug,l as Uh,m as Lh,r as Bh,s as Hh,w as zh,x as Pt}from"./chunk-U4YN7DB7.js";import{a as Ug}from"./chunk-ZATQYC4Y.js";import{a as Wt}from"./chunk-3HGEDPEP.js";import{a as mt,b as qt}from"./chunk-JDLRIKAZ.js";import{A as P,B as F,a as Og,b as Eg,u as Pb,y as Fb,z as Ag}from"./chunk-3J52NZMN.js";import{a as Be,b as Mg}from"./chunk-4ACOV475.js";import{a as Ab,b as W,c as Jr,d as Ut}from"./chunk-WTYACTR5.js";import{a as Hb}from"./chunk-6E3N35RF.js";import{a as Dr}from"./chunk-KEM6PWSD.js";import{a as Fh}from"./chunk-UJRDSNTY.js";import{A as nn,F as Eh,G as gt,H as bt,I as Mh,Y as Gh,ba as jh,ca as $t,da as D,ea as Et,f as dg,fa as xe,ga as At,j as Sh,m as Fv,n as vg,p as yh,r as cg,s as Th,t as mg,v as Oh}from"./chunk-KU45CEXD.js";import{$ as et,$b as rn,$f as un,A as nh,Aa as Ir,Ab as pr,Bb as hr,Bf as wo,Bg as db,C as oh,Ca as ur,Ce as Ur,Cf as mr,Cg as zr,D as Eu,Db as ft,De as it,Df as xg,Dg as vb,E as jt,Ea as Qs,Eb as Ct,Ec as jr,Ed as Nh,Ee as X,Ef as Uv,Fa as d,Fb as kt,Fc as It,Ff as dr,G as yn,Ga as Le,Gb as In,Gc as ge,Gf as Mn,Gi as Mb,Ha as eg,Hb as Mv,Hf as sr,I as Ov,Ia as ch,Ib as we,If as An,Ig as Io,Ih as ln,Ii as to,J as Jn,Jb as at,Jf as Pn,Jg as Rc,Jh as $u,Kb as ue,Ke as fg,Kf as Fu,Kg as Uc,L as gr,Lc as qe,Lf as Kh,M as wn,Ma as tg,Mb as Av,Mf as gn,N as ah,Nb as le,Nc as Pv,Nf as Zh,Nh as Dg,O as ih,Oa as Ev,Ob as je,Oc as sn,Od as Rh,Oe as Yt,Of as zt,Oh as pb,Pa as j,Pb as Ce,Pc as xh,Pe as En,Ph as hb,Q as Zs,Qb as og,Qe as Nt,Qh as bb,R as lh,Ra as mh,Rb as bh,Re as Jh,Rf as Nu,Rh as fb,S as Mu,Se as qn,Sf as on,Sh as Cb,T as Me,Ta as sh,Td as Kn,Tf as Xh,Th as kb,Ua as T,Ud as Zn,Uf as qh,Uh as xb,Va as gh,Vf as Qh,Vh as Tg,W as Ac,Wa as uh,Wd as Au,Wf as eb,Wh as Bv,Xc as _h,Xd as Ke,Y as Pc,Ya as M,Yb as fh,Yh as _b,Zb as ag,Zd as dt,Ze as Qn,Zf as Nc,Zg as cb,_ as Xs,_a as s,_b as U,_f as _g,_g as mb,_h as Do,a as g,aa as dh,ac as ct,ae as hg,ag as an,ah as wg,b as f,ba as vh,bb as rg,bc as ce,bg as Ru,bh as Lv,bi as fr,ca as be,cc as C,cg as tb,ci as vr,da as se,db as k,dc as fe,di as N,eb as Gr,ec as Je,ef as Cg,eg as rb,ei as Vv,fb as y,fc as O,fg as Sg,fh as ye,g as Pe,gb as w,gc as St,h as qp,ha as B,hb as ph,hc as Yn,hg as Uu,hh as Ig,hi as Sb,i as Qp,ia as V,ib as ng,if as Yh,ig as yg,ih as sb,ii as wb,ja as de,jb as rt,jc as Dn,jg as Lu,jh as Wr,k as Gt,ka as xt,kb as nt,kc as A,kg as eo,l as De,la as qs,lb as v,lc as R,lh as Lc,li as Ne,m as eh,mb as b,mc as Er,mi as ot,nb as x,nc as Ch,ni as Mr,o as th,ob as E,oc as kh,oe as ke,oh as Bc,oi as Ib,p as Wn,pc as Ge,pd as br,pe as bg,pg as nb,q as _n,qa as Fe,qe as On,qg as ob,qi as Xt,r as Ee,rc as ig,rf as Fc,rh as gb,ri as Db,sb as u,sc as L,se as Hr,sh as Bu,si as Qe,tb as p,tc as yt,te as Nv,th as ub,ti as Tb,ua as tt,ub as ze,uc as or,uf as kg,ug as ab,v as Oe,va as Y,vb as J,vc as q,ve as Pu,vg as ib,vh as ne,w as kr,wa as me,wb as hh,wc as Tn,we as lr,wg as lb,wh as Vu,wi as Ob,x as rh,xb as H,xc as ar,xe as Rv,ye as Wh,yi as ut,z as Sn,zb as l,zc as lg,ze as Xn,zi as Eb}from"./chunk-GR3NESUB.js";var Dt=(()=>{let o=class o{constructor(e){this.loggingService=e,this._customStatusMap=new De(X.CommentAnnotationStatusMap),this._customPriorityMap=new De(X.CommentAnnotationPriorityMap),this._customCategoryMap=new De(X.CommentCategoryMap);try{let t=sessionStorage.getItem(X.SESSION_STORAGE.VELT_CUSTOM_PRIORITY_MAP);t&&this._customPriorityMap.next(JSON.parse(t));let a=sessionStorage.getItem(X.SESSION_STORAGE.VELT_CUSTOM_STATUS_MAP);a&&this._customStatusMap.next(JSON.parse(a));let i=sessionStorage.getItem(X.SESSION_STORAGE.VELT_CUSTOM_CATEGORY_MAP);i&&this._customCategoryMap.next(JSON.parse(i))}catch(t){this.loggingService.catch("Error in CustomFilterService constructor: ",t)}}setCustomStatusFilters(e){try{if(e.length<2){this._customStatusMap.next(X.CommentAnnotationStatusMap),sessionStorage.setItem(X.SESSION_STORAGE.VELT_CUSTOM_STATUS_MAP,JSON.stringify(X.CommentAnnotationStatusMap)),this.loggingService.catch("Custom status filters must have at least 2 filters");return}let t={};e.forEach(a=>{t[a.id]=a,a.type||(a.type="ongoing")}),this._customStatusMap.next(t),sessionStorage.setItem(X.SESSION_STORAGE.VELT_CUSTOM_STATUS_MAP,JSON.stringify(t))}catch(t){this.loggingService.catch("Error in CustomFilterService setCustomStatusFilters: ",t)}}setCustomPriorityFilters(e){try{if(e.length<2){this._customPriorityMap.next(X.CommentAnnotationPriorityMap),sessionStorage.setItem(X.SESSION_STORAGE.VELT_CUSTOM_PRIORITY_MAP,JSON.stringify(X.CommentAnnotationPriorityMap)),this.loggingService.catch("Custom priority filters must have at least 2 filters");return}let t={};e.forEach(a=>{t[a.id]=a}),this._customPriorityMap.next(t),sessionStorage.setItem(X.SESSION_STORAGE.VELT_CUSTOM_PRIORITY_MAP,JSON.stringify(t))}catch(t){this.loggingService.catch("Error in CustomFilterService setCustomPriorityFilters: ",t)}}setCustomCategories(e){try{let t={};e.forEach(a=>{t[a.id]=a}),this._customCategoryMap.next(t),sessionStorage.setItem(X.SESSION_STORAGE.VELT_CUSTOM_CATEGORY_MAP,JSON.stringify(t))}catch(t){this.loggingService.catch("Error in CustomFilterService setCustomCategories: ",t)}}get customStatusMap$(){return this._customStatusMap.asObservable()}get customPriorityMap$(){return this._customPriorityMap.asObservable()}get customCategoryMap$(){return this._customCategoryMap.asObservable()}get defaultStatus(){try{let t=Object.entries(this._customStatusMap.value).find(([a,i])=>i.type==="default");if(t)return t[1]}catch(e){this.loggingService.catch("Error in CustomFilterService defaultStatus: ",e)}return X.CommentAnnotationStatusMap.OPEN}get resolvedStatus(){try{let t=Object.entries(this._customStatusMap.value).find(([a,i])=>i.type==="terminal");if(t)return t[1]}catch(e){this.loggingService.catch("Error in CustomFilterService resolvedStatus: ",e)}return X.CommentAnnotationStatusMap.OPEN}get ongoingStatuses(){try{let t=Object.entries(this._customStatusMap.value).filter(([a,i])=>i.type==="ongoing");if(t)return t.map(a=>a[1])}catch(e){this.loggingService.catch("Error in CustomFilterService ongoingStatuses: ",e)}return[X.CommentAnnotationStatusMap.IN_PROGRESS]}get terminalStatuses(){try{return Object.entries(this._customStatusMap.value).filter(([t,a])=>a.type==="terminal").map(t=>t[1])}catch(e){this.loggingService.catch("Error in CustomFilterService terminalStatuses: ",e)}return[]}convertLegacyAnnotationStatus(e){try{if(typeof e.status=="string"||e.status===void 0){let t=Object.entries(this._customStatusMap.value),a=t.find(([i,c])=>c.type==="default");switch(e.status){case"open":a&&(e.status=a[1]);break;case"inProgress":let i=t.find(([m,h])=>h.type==="ongoing");i&&(e.status=i[1]);break;case"resolved":let c=t.find(([m,h])=>h.type==="terminal");c&&(e.status=c[1]);break;default:a&&(e.status=a[1]);break}}return e}catch(t){return this.loggingService.catch("Error in CustomFilterService convertLegacyAnnotation: ",t),e}}convertLegacyPriority(e){try{typeof e.priority=="string"&&(e.priority=X.CommentAnnotationPriorityMap[e.priority])}catch(t){this.loggingService.catch("Error in CustomFilterService convertLegacyPriority: ",t)}return e}convertLegacyCategory(e){try{if(e.commentCategories===void 0||e.commentCategories===null||!Array.isArray(e.commentCategories)||e.commentCategories.length===0)return e;typeof e.commentCategories[0]=="string"&&(e.commentCategories=e.commentCategories.map(t=>X.CommentCategoryMap[t]))}catch(t){this.loggingService.catch("Error in CustomFilterService convertLegacyCategory: ",t)}return e}};o.\u0275fac=function(t){return new(t||o)(be(N))},o.\u0275prov=et({token:o,factory:o.\u0275fac,providedIn:"root"});let r=o;return r})();var Yb=(()=>{let o=class o{constructor(e,t){this.domService=e,this.loggingService=t,this.keyEventSubject$=new Gt;try{this.loggingService.log("%c[WB] Creating CLASS: HotkeyService","color: blue;"),this.keyEvent$=this.keyEventSubject$.asObservable().pipe(ih()),this.domService.onWindowKeydown$().subscribe(a=>{this.keyEventSubject$.next(a)})}catch(a){this.loggingService.catch("Error in HotkeyService constructor: ",a)}}getKeyPressEvent(e,t={}){try{return this.loggingService.log("%c[WB] Calling FUNCTION: getKeyPressEvent","color: green;"),this.keyEvent$.pipe(jt(a=>a?.key===e),jt(a=>!(!!t?.includeCtrl!==a.ctrlKey||!!t?.includeAlt!==a.altKey||!!t?.includeShift!==a.shiftKey||!!t?.includeMeta!==a.metaKey)),jt(()=>this.isNoInputFocused()))}catch(a){return this.loggingService.catch("Error in HotkeyService getKeyPressEvent: ",a),new Qp}}isNoInputFocused(){try{let e=document.activeElement;for(;e?.shadowRoot?.activeElement;)e=e.shadowRoot.activeElement;for(;e&&e?.tagName!=="BODY";){if(e.tagName==="INPUT"||e.tagName==="TEXTAREA"||e?.isContentEditable)return!1;e=e.parentElement??e.getRootNode()?.host??null}return!0}catch(e){return this.loggingService.catch("Error in HotkeyService isNoInputFocused: ",e),!1}}};o.\u0275fac=function(t){return new(t||o)(be(Ne),be(N))},o.\u0275prov=et({token:o,factory:o.\u0275fac,providedIn:"root"});let r=o;return r})();var Dy=["access","accessFields"];function Ty(r){return r?Object.keys(r).length>0:!1}var ie=(()=>{let o=class o{constructor(e,t,a,i,c,m,h,_,I,S,z,$,G,Z,ae,pe,Se,oe,he,_e,Re,Ye,lt,Xe){this.analyticsService=e,this.commonDbService=t,this.configService=a,this.docService=i,this.databaseService=c,this.authService=m,this.domService=h,this.afAuth=_,this.avatarService=I,this.contactService=S,this.storageService=z,this.functions=$,this.dialog=G,this.iamService=Z,this.loggingService=ae,this.notificationService=pe,this.customFilterService=Se,this.hotkeyService=oe,this.serviceBook=he,this.buttonService=_e,this.metadataService=Re,this.commonDbUtilsService=Ye,this.attachmentResolverService=lt,this.userPermissionService=Xe,this.endpointsService=se(Sb),this.customPinsById=new Map,this.commentAdded$=new Gt,this.commentUpdated$=new Gt,this.commentAccepted$=new Gt,this.commentRejected$=new Gt,this.commentAnnotationDeleted$=new Gt,this.multiThreadCommentAnnotationDeleted$=new Gt,this.commentAnnotationById$=new De(null),this.multiThreadCommentAnnotationById$=new De(null),this.ghostCommentAnnotationMap$=new De({}),this.unreadCommentsMap$=new De(null),this.documentPaths=null,this.user=null,this.customCategoryMap=X.CommentCategoryMap,this.allowedElementIds$=new De([]),this.allowedElementClassNames$=new De([]),this.allowedElementQuerySelectors$=new De([]),this.addCommentMode$=new De(!1),this.persistentCommentMode$=new De(!1),this.seenByUsers$=new De(!0),this.deleteReplyConfirmation$=new De(!1),this.persistentModeBanner$=new De(!0),this.commentAddedEmitter=null,this.commentContextProvider=null,this.textCommentMode$=new De(!0),this.sidebarVisible$=new De(!1),this.sidebarOpenedByCustomTrigger$=new De(!1),this.floatingCommentsEnabled$=new De(!0),this.moderatorMode$=new De(!1),this.streamMode$=new De(!1),this.enableSignInButton$=new De(!1),this.enableUpgradeButton$=new De(!1),this.onSignInClick$=new Gt,this.onUpgradeClick$=new Gt,this.enableAttachment$=new De(!0),this.enableAttachmentDownload$=new De(!0),this.enableReactions$=new De(!0),this.enableAnonymousEmail$=new De(!0),this.enableFormatOptions$=new De(!1),this.formatConfig$=new De({bold:{enable:!0},italic:{enable:!0},underline:{enable:!0},strikethrough:{enable:!0}}),this.allowedRecordings$=new De(["audio","video","screen"]),this.openSidebar$=new Gt,this.showScreenSizeInfo$=new De(!1),this.showCommentIndex$=new De(!1),this.popoverMode$=new De(!1),this.popoverTriangleComponent$=new De(!0),this.draftMode$=new De(!0),this.enableDialogOnHover$=new De(!0),this.enableDialogOnTargetElementClick$=new De(!1),this.enablePriority$=new De(!1),this.enableStatus$=new De(!0),this.visibilityOptions$=new De(!1),this.enableResolve$=new De(!0),this.enableGhostComments$=new De(!1),this.enableGhostCommentsMessage$=new De(!0),this.inboxMode$=new De(!1),this.enableAutoCategorize$=new De(!1),this.commentContainerDarkMode$=new De(!1),this.suggestionMode$=new De(!1),this.mobileMode$=new De(!0),this.inlineCommentMode$=new De(!1),this.minimap$=new De(!1),this.commentsOnDom$=new De(!0),this.commentToolEnabled$=new De(!0),this.totalMediaLength$=new De(0),this.sidebarUrlNavigationEnabled$=new De(!1),this.detectionStrategy$=new De(Pu.DEFAULT),this.sidebarButtonOnCommentDialogVisible$=new De(!1),this.sidebarButtonOnCommentDialogClick$=new Gt,this.commentNavigationButtonClick$=new Gt,this.deviceIndicatorOnCommentPins$=new De(!1),this.sidebarCommentClick$=new Gt,this.privateCommentMode$=new De(!1),this.privateCommentAllowed$=new De(!1),this.privateModeConfig$=new De(null),this.scrollToComment$=new De(!0),this.userMentions$=new De(!0),this.paginatedContactList$=new De(!1),this.deleteOnBackspace$=new De(!0),this.hotkeyEnabled$=new De(!1),this.recordingSummaryEnabled$=new De(!0),this.unreadIndicatorMode$=new De(Rv.MINIMAL),this.composerMode$=new De(Wh.DEFAULT),this.enterKeyToSubmit$=new De(!1),this.resolvedCommentsOnDom$=new De(!1),this.bubbleOnPinEnabled$=new De(!1),this.bubbleOnPinHoverEnabled$=new De(!0),this.pinDragEnabled$=new De(!0),this.excludeLocationIdsFromSidebar$=new De([]),this.multiThread$=new De(!1),this.groupMatchedComments$=new De(!1),this.restrictTextSearchToAnchor$=new De(!1),this.shortUserName$=new De(!0),this.collapsedComments$=new De(!1),this.collapsedRepliesPreview$=new De(!1),this.fullExpanded$=new De(!1),this.queryParamsComments$=new De(!1),this.resolveStatusAccessAdminOnly$=new De(!1),this.linkCallback$=new De(!1),this.svgAsImg$=new De(!1),this.commentToNearestAllowedElement$=new De(!1),this.filterCommentsOnDom$=new De(!1),this.maxReplyAvatars$=new De(3),this.replyAvatars$=new De(!1),this.commentplaceholder$=new De(void 0),this.replyplaceholder$=new De(void 0),this.editplaceholder$=new De(void 0),this.editcommentplaceholder$=new De(void 0),this.editreplyplaceholder$=new De(void 0),this.screenshotEnabled$=new De(!1),this.pinShadowDOM$=new De(!0),this.dialogShadowDOM$=new De(!0),this.dialogShadowDOMExplicit$=new De(void 0),this.textCommentToolShadowDOM$=new De(!0),this.pinDarkMode$=new De(null),this.textCommentToolDarkMode$=new De(null),this.textCommentToolbarDarkMode$=new De(null),this.textCommentToolbarShadowDOM$=new De(!0),this.sidebarShadowDOM$=new De(!0),this.changeDetectionInCommentMode$=new De(!1),this.commentSelectionChange$=new Gt,this.visibilityOptionClicked$=new Gt,this.submitComment$=new Gt,this.clearComposer$=new Gt,this.composerDataMap=new Map,this.commentsFromSidebarMap$=new De(null),this.sidebarButtonCountType$=new De("default"),this.filterGhostCommentsInSidebar$=new De(!1),this.commentSidebarFilters$=new De(null),this.effectiveSidebarFilters$=new De({}),this.customSidebarDataAnnotationIds$=new De(null),this.commentSidebarSystemFiltersOperator$=new De(Ur.AND),this.bubbleCommentAnnotationIds$=new De([]),this.updateCommentDialogPositionTriggerSubject$=new De(void 0),this.areaCommentEnabled$=new De(!0),this.commentPinCursorImage$=new De(""),this.commentAnnotationsFromCommentsContainer$=new De([]),this.customChipDropdownData$=new De(null),this.originalCommentAnnotationsByDocumentId$=new De({}),this.draftCommentAnnotationsByAnnotationId$=new De(null),this.draftMultiThreadCommentAnnotationsByAnnotationId$=new De({}),this.pendingAddCommentAnnotationData=new Map,this.copyLink$=new De(""),this.addCommentDragMode=!1,this.dragSubscriptions=[],this.hotkeySubscriptions=[],this.sidebarData$=new De(null),this.sidebarCustomActionEventData$=new De(null),this.sidebarCustomActionEventDataAllChanges$=new De(null),this.sidebarCustomActionEventDataOnInit$=new De(null),this.customActions$=new De(!1),this.focusedThreadMode$=new De(!1),this.openAnnotationInFocusMode$=new De(!1),this.customStatusesShown$=new De(!1),this.readOnly$=new De(!1),this.customAutocompleteSearch$=new De(!1),this.deleteThreadWithFirstComment$=new De(!0),this.assignToType$=new De("dropdown"),this.pageModeComposerContext$=new De(null),this.contextInPageModeComposer$=new De(!1),this.focusPageModeComposer$=new Gt,this.transformContext$=new De(null),this.expandMentionGroups$=new De(!1),this.showMentionGroupsFirst$=new De(!1),this.showMentionGroupsOnly$=new De(!1),this.fullScreenInSidebar$=new De(!1),this.composerFileAttachments$=new De(null),this.attachmentNameInMessage$=new De(!1),this.allowedFileTypes$=new De([]),this.forceCloseAllOnEsc$=new De(!1),this.autoCompleteScrollConfig$=new De({itemSize:55,minBufferPx:350,maxBufferPx:600,templateCacheSize:350}),this.commentAnnotationContextDraft=null,this.reactionService=null,this.areaService=null,this.viewsService=null,this.getCommentAnnotationForClient=Ve=>{try{let ht=["commentCategories","color","resolved","inProgress","positionX","positionY","screenWidth","screenHeight","screenScrollHeight","screenScrollTop","taggedElementPath","taggedElementRect","targetElement","position","documentParamsId","documentParams","ghostComment","areaAnnotationId","iam","commentSource","involvedUserIds","mentionedUserIds","viewedByUserIds","views"],Ze=JSON.parse(JSON.stringify(Ve)),Tt={};Object.keys(Ze).forEach(Lt=>{ht.includes(Lt)||(Tt[Lt]=Ze[Lt])}),Tt?.comments?.forEach(Lt=>{let We=[];Lt?.reactionAnnotationIds&&Lt?.reactionAnnotationIds?.forEach(Tu=>{let Ks=this.reactionService?.getAnnotationById(Tu);if(Ks){let Mc=this.reactionService.getReactionAnnotationForClient(Ks);We.push(Mc)}}),Lt.reactionAnnotations=We}),Ze?.viewedByUserIds?.forEach(Lt=>{let We=this.contactService.getUserBySnippylyId(Lt);We&&(Tt.viewedBy||(Tt.viewedBy=[]),Tt.viewedBy.push(We))}),this.user?.userSnippylyId&&(Tt.unread=!Ze?.viewedByUserIds?.includes(this.user.userSnippylyId));let Ue=Ze?.targetElement?.anchor?.fXPath||Ze?.targetElement?.fXpath;return Ue&&(Tt.basicAnchorData={xpath:Ue,topPercentage:Ze?.targetElement?.topPercentage||0,leftPercentage:Ze?.targetElement?.leftPercentage||0}),JSON.parse(JSON.stringify(Tt))}catch{return null}},this.loggingService.log("%c[WB] Creating CLASS: CommentService","color: blue;"),this.serviceBook.set(Dg,this),this.serviceBook.observe(Tg).subscribe(Ve=>{this.reactionService=Ve}),this.serviceBook.observe(_b).subscribe(Ve=>{this.areaService=Ve}),this.serviceBook.observe(Do).subscribe(Ve=>{this.viewsService=Ve}),this.domService.getSelectedAnnotationsMap$().pipe(Ov(100),wn()).subscribe(([Ve,ht])=>{try{if(this.draftCommentAnnotationsByAnnotationId$.value){let Ze=Object.keys(this.draftCommentAnnotationsByAnnotationId$.value||{}),Tt=[];Object.keys(Ve||{}).forEach(Lt=>{!ht?.[Lt]&&Ze.includes(Lt)&&Tt.push(Lt)});let Ue=JSON.parse(JSON.stringify(this.draftCommentAnnotationsByAnnotationId$.value||{}));Tt.forEach(Lt=>{delete Ue[Lt]}),an(Ue,this.draftCommentAnnotationsByAnnotationId$.value)||this.draftCommentAnnotationsByAnnotationId$.next(Ue)}}catch{}}),this.docService.getDocumentPaths$().pipe(wn()).subscribe(([Ve,ht])=>{Ve?.documentId!==ht?.documentId&&this.unreadCommentsMap$.next(null),ht&&this.shouldEnableReadOnly()},Ve=>{this.loggingService.catch("Error in CommentService getDocumentPaths$ subscription: ",Ve)}),this.draftCommentAnnotationsByAnnotationId$.pipe(wn()).subscribe(([Ve,ht])=>{try{if(this.pendingAddCommentAnnotationData.size===0)return;let Ze=Object.keys(Ve||{});if(Ze.length===0)return;let Tt=new Set(Object.keys(ht||{}));Ze.forEach(Ue=>{!Tt.has(Ue)&&this.pendingAddCommentAnnotationData.has(Ue)&&this.pendingAddCommentAnnotationData.delete(Ue)})}catch(Ze){this.loggingService.catch("Error in CommentService pendingAddCommentAnnotationData reconcile: ",Ze)}}),this.authService.getUser$().subscribe(Ve=>{Ve||this.resetCacheData()},Ve=>{this.loggingService.catch("Error in CommentService getUser$ subscription: ",Ve)}),this.authService.getUser$().pipe(Me(Ve=>Ve?kr([this.iamService.isUserAdmin$(),this.contactService.getUserOrganizationContacts$()]).pipe(Oe(([ht,Ze])=>{let Tt=!1;return Ze?.find(Ue=>Ue.userId===Ve?.userId)&&(Tt=!0),{isUserAdmin:ht,isOrgUser:Tt}})):Ee({isUserAdmin:!1,isOrgUser:!1}))).subscribe(({isUserAdmin:Ve,isOrgUser:ht})=>{let Ze=Ve||ht;Ze!==this.privateCommentAllowed$.value&&this.privateCommentAllowed$.next(Ze)}),this.databaseService.getDb().pipe(jt(Ve=>!!Ve),Jn(1)).subscribe(Ve=>{Ve&&this.getDocumentPaths()},Ve=>{this.loggingService.catch("Error in CommentService getDb subscription: ",Ve)}),this.domService.onWindowPointerMove$().subscribe(Ve=>{if(this.addCommentMode$.value){let ht=!0;if(this.addCommentDragMode)this.domService.removeClassFromElement(document.body,"show-pin-cursor");else{let Ze=this.domService.getBackgroundElement(Ve.clientX,Ve.clientY,!0,!0);if(Ze&&ub(Ze,{x:Ve.clientX,y:Ve.clientY})&&(Ze=Ze?.parentElement),Ze)if(this.isElementInsideAllowedElements(Ze))if(eo(Ve.target))this.domService.removeClassFromElement(document.body,"show-pin-cursor");else{this.domService.addClassToElement(document.body,"show-pin-cursor"),this.hightlightElement&&this.hightlightElement!==Ze&&this.domService.removeHighlightFromElement(this.hightlightElement),this.hightlightElement=Ze;let Tt=this.domService.getSelectedAnnotationsMap("comment")||{},Ue=this.commentPinCursorImage$.value||X.CURSOR.COMMENT_PIN;this.domService.highlightElement(this.hightlightElement,Ue,!!Object.keys(Tt)?.length),ht=!1}else this.domService.removeClassFromElement(document.body,"show-pin-cursor")}this.hightlightElement&&ht&&(this.domService.removeHighlightFromElement(this.hightlightElement),this.hightlightElement=null)}},Ve=>{this.loggingService.catch("Error in CommentService onWindowPointerMove$ subscription: ",Ve)}),this.domService.onWindowKeyupEsc$().subscribe(Ve=>{if(this.addCommentMode$.value){let ht=this.domService.getSelectedAnnotationsMap("comment")||{};Object.keys(ht)?.length&&this.domService.resetSelectedAnnotationsMap(),this.disableAddCommentMode()}},Ve=>{this.loggingService.catch("Error in CommentService onWindowKeyupEsc$ subscription: ",Ve)}),this.domService.onDocumentClick$().subscribe(Ve=>{if(Ve&&!_g(Ve)){let ht=this.domService.getSelectedAnnotationsMap("comment")||{};if(ht=g(g({},ht),this.domService.getSelectedAnnotationsMap("multiThread")||{}),ht=g(g({},ht),this.domService.getSelectedAnnotationsMap("suggestion")||{}),Object.keys(ht)?.length&&(this.domService.resetSelectedAnnotationsMap(),this.persistentCommentMode$?.value)){this.addCommentMode$.value&&this.detectToAddAreaComment(),Ve.preventDefault(),Ve.stopPropagation();return}}if(Ve&&this.addCommentMode$.value&&!eo(Ve.target)){let ht=!1;if(this.addCommentDragMode)Ve.preventDefault(),Ve.stopPropagation(),this.addCommentDragMode=!1;else if(!this.domService.getDraftCommentAnnotationDialogs()?.length){let Ze=this.domService.getBackgroundElement(Ve.clientX,Ve.clientY);if((this.persistentCommentMode$?.value&&this.domService.getBackgroundVeltElement(Ve.clientX,Ve.clientY)||Ve&&_g(Ve))&&(Ze=null),Ze&&(this.isElementInsideAllowedElements(Ze)||this.getCommentToNearestAllowedElement()&&this.getNearestAllowedElement(Ze))&&(ht=this.isElementInsideManualCommentContainer(Ze),!ht)){Ve.preventDefault(),Ve.stopPropagation();let Tt=this.freeStyleCommentContext&&typeof this.freeStyleCommentContext=="object"?JSON.parse(JSON.stringify(this.freeStyleCommentContext)):void 0;this.addComment(Ve,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,Tt)}}this.persistentCommentMode$?.value?this.detectToAddAreaComment():ht||this.disableAddCommentMode()}},Ve=>{this.loggingService.catch("Error in CommentService onDocumentClick$ subscription: ",Ve)}),this.addCommentMode$.subscribe(Ve=>{this.hightlightElement&&this.domService.removeHighlightFromElement(this.hightlightElement),Ve?(this.domService.addClassToElement(document.body,"snippyly-add-comment-mode"),this.detectToAddAreaComment(),this.addIframeContainerStaticAttribute()):(this.removeIframeContainerStaticAttribute(),this.domService.removeClassFromElement(document.body,"snippyly-add-comment-mode"),this.domService.removeClassFromElement(document.body,"show-pin-cursor"),this.dragSubscriptions.forEach(ht=>ht.unsubscribe()),this.clearFreeStyleCommentContext())},Ve=>{this.loggingService.catch("Error in CommentService addCommentMode$ subscription: ",Ve)}),this.domService.onWindowKeyupBackspace$().subscribe(Ve=>{this.getDeleteOnBackspace()&&this.deleteCommentPinAnnotations("keyupBackspace")},Ve=>{this.loggingService.catch("Error in CommentService onWindowKeyupBackspace$ subscription: ",Ve)}),this.domService.onWindowKeyupDelete$().subscribe(Ve=>{this.deleteCommentPinAnnotations("keyupDelete")},Ve=>{this.loggingService.catch("Error in CommentService onWindowKeyupDelete$ subscription: ",Ve)}),this.domService.getDeleteCommmentAnnotations$().subscribe(Ve=>{Ve?.length&&(Ve?.filter(Ze=>!["tag","recorder","rewriter","arrow","area","multiThread"].includes(Ze.type))).forEach(Ze=>Pe(this,null,function*(){yield this.deleteCommentPinAnnotation(Ze)}))},Ve=>{this.loggingService.catch("Error in CommentService onWindowKeyupDelete$ subscription: ",Ve)}),this.getPopoverMode$().subscribe(Ve=>{Ve?document?.body?.setAttribute(X.ATTRIBUTES.VELT_POPOVER_MODE,"true"):document?.body?.removeAttribute(X.ATTRIBUTES.VELT_POPOVER_MODE)},Ve=>{this.loggingService.catch("Error in CommentService getPopoverMode subscription: ",Ve)}),this.customFilterService.customCategoryMap$.subscribe(Ve=>{this.customCategoryMap=Ve},Ve=>{this.loggingService.catch("Error in CommentService customCategoryMap$ subscription: ",Ve)}),this.hotkeyEnabled$.subscribe(Ve=>{Ve?this.subscribeHotkeyEvents():this.unsubscribeHotkeyEvents()},Ve=>{this.loggingService.catch("Error in CommentService hotkeyEnabled$ subscription: ",Ve)}),this.domService.getSelectedAnnotationsMap$().pipe(wn()).subscribe(([Ve,ht])=>{try{let Ze=Object.values(Ve||{}).filter(Ue=>!["tag","recorder","rewriter","arrow","area"].includes(Ue.type)),Tt=Object.values(ht||{}).filter(Ue=>!["tag","recorder","rewriter","arrow","area"].includes(Ue.type));Ze?.forEach(Ue=>{Tt?.find(Lt=>Lt.annotationId===Ue.annotationId)||this.commentSelectionChange$.next({annotation:this.getCommentAnnotationForClient(Ue),selected:!1})}),Tt?.forEach(Ue=>{Ze?.find(Lt=>Lt.annotationId===Ue.annotationId)||this.commentSelectionChange$.next({annotation:this.getCommentAnnotationForClient(Ue),selected:!0})})}catch(Ze){this.loggingService.catch("Error in CommentService getSelectedAnnotationsMap$: ",Ze)}},Ve=>{this.loggingService.catch("Error in CommentService getSelectedAnnotationsMap$ subscription: ",Ve)})}clearCache(){try{this.loggingService.log("%c[WB] Calling FUNCTION: clearCache in CommentService","color: green;"),this.commentAnnotationById$.next(null),this.draftCommentAnnotationsByAnnotationId$.next(null),this.multiThreadCommentAnnotationById$.next({}),this.draftMultiThreadCommentAnnotationsByAnnotationId$.next({}),this.pendingAddCommentAnnotationData.clear(),this.customAutocompleteSearch$.next(!1),this.hightlightElement=null,this.addCommentMode$.next(!1),this.unreadCommentsMap$.next(null),this.documentPaths=null,this.commentsFromSidebarMap$.next(null),this.customSidebarDataAnnotationIds$.next(null)}catch(e){this.loggingService.catch("Error in CommentService clearCache: ",e)}}setCommentActionsService(e){try{this.commentActionsService=e}catch(t){this.loggingService.catch("Error in CommentService setCommentActionsService: ",t)}}detectToAddAreaComment(){try{let e=this.areaService?.getAreaEnabled()??!1,t=this.getAreaCommentEnabled();if(e&&t){let a,i,c,m=null,h=null;this.dragSubscriptions.forEach(_=>_.unsubscribe()),this.dragSubscriptions.push(this.domService.onWindowMouseDown$().pipe(jt(_=>!(_&&_g(_))),Jn(1)).subscribe(_=>{m=null,h=null,this.dragSubscriptions.push(this.domService.getClickAndDragPointsObservable().subscribe(I=>{if(m===null){let S=I?.startPoint?.event?.target,z=Nc(S),$=eo(S),G=this.isElementInsideAllowedElements(S);m=!z&&!$&&G}if(m){this.addCommentDragMode=!0,a=I.startPoint,i=I.curPoint;let S=I?.curPoint?.event?.target,z=Nc(S),$=eo(S),G=this.isElementInsideAllowedElements(S);h=!z&&!$&&G,h?c=this.domService.drawRectangle(a,i):c?.remove()}})),this.domService.onWindowPointerUp$().pipe(Zs(1),Jn(1)).subscribe(I=>{if(i={x:I.clientX,y:I.clientY},a&&i&&(c?.remove(),m&&h)){let S=[{x:a.x-window.scrollX,y:a.y-window.scrollY},{x:i.x,y:i.y}],z=this.freeStyleCommentContext&&typeof this.freeStyleCommentContext=="object"?JSON.parse(JSON.stringify(this.freeStyleCommentContext)):void 0;this.addComment(I,void 0,S,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,z)}this.dragSubscriptions.forEach(S=>S.unsubscribe())})}))}}catch(e){this.loggingService.catch("Error in CommentService detectToAddAreaComment: ",e)}}resetCacheData(){try{this.loggingService.log("%c[WB] Calling CommentService FUNCTION: resetCacheData","color: green;"),this.commentAnnotationById$.next(null),this.draftCommentAnnotationsByAnnotationId$.next(null),this.multiThreadCommentAnnotationById$.next({}),this.draftMultiThreadCommentAnnotationsByAnnotationId$.next({}),this.pendingAddCommentAnnotationData.clear()}catch(e){this.loggingService.catch("Error in CommentService resetCacheData: ",e)}}addAreaContainerTag(){try{if(!(document.querySelector(X.TAGS.VELT_AREAS)||document.querySelector(X.TAGS.SNIPPYLY_AREAS))){let t=document.createElement(X.TAGS.VELT_AREAS);document.body.appendChild(t)}}catch(e){this.loggingService.catch("Error in CommentService addAreaContainerTag: ",e)}}addIframeContainerStaticAttribute(){try{document.querySelectorAll(`[${X.ATTRIBUTES.VELT_IFRAME_CONTAINER}]`).forEach(t=>{window.getComputedStyle(t).position==="static"&&t.setAttribute(X.ATTRIBUTES.VELT_IFRAME_CONTAINER_STATIC,"true")})}catch(e){this.loggingService.catch("Error in CommentService addIframeContainerStaticAttribute: ",e)}}removeIframeContainerStaticAttribute(){try{document.querySelectorAll(`[${X.ATTRIBUTES.VELT_IFRAME_CONTAINER_STATIC}]`).forEach(t=>{t.removeAttribute(X.ATTRIBUTES.VELT_IFRAME_CONTAINER_STATIC)})}catch(e){this.loggingService.catch("Error in CommentService removeIframeContainerStaticAttribute: ",e)}}subscribeHotkeyEvents(){try{this.loggingService.log("%c[WB] Calling FUNCTION: subscribeHotkeyEvents","color: green;"),this.unsubscribeHotkeyEvents(),this.hotkeySubscriptions.push(this.hotkeyService.getKeyPressEvent("c").subscribe(e=>{e&&!this.addCommentMode$.value&&this.enableAddCommentMode()},e=>{this.loggingService.catch("Error in CommentService hotkeyService.getKeyPressEvent subscription: ",e)}))}catch(e){this.loggingService.catch("Error in CommentService subscribeHotkeyEvents: ",e)}}unsubscribeHotkeyEvents(){try{this.loggingService.log("%c[WB] Calling FUNCTION: unsubscribeHotkeyEvents","color: green;"),this.hotkeySubscriptions.forEach(e=>e?.unsubscribe())}catch(e){this.loggingService.catch("Error in CommentService unsubscribeHotkeyEvents: ",e)}}setCommentAddedEmitter(e){try{this.commentAddedEmitter=e}catch(t){this.loggingService.catch("Error in CommentService setCommentAddedEmitter: ",t)}}setContextProvider(e){try{this.commentContextProvider=e}catch(t){this.loggingService.catch("Error in CommentService setContextProvider: ",t)}}getDocumentPaths(){this.loggingService.log("%c[WB] Calling FUNCTION: getDocumentPaths","color: green;"),this.docService.getDocumentPaths$()}getAnonymousAvatarImage(){return this.loggingService.log("%c[WB] Calling FUNCTION: getAnonymousAvatarImage","color: green;"),this.avatarService.generateUserImage()}setAllowedElementIds(e){try{this.analyticsService.setFeatureConfig({feature:ke.COMMENT,config:{allowedElementIds:e}}),this.allowedElementIds$.next(e||[])}catch(t){this.loggingService.catch("Error in CommentService setAllowedElementIds: ",t)}}getAllowedElementIds(){return this.allowedElementIds$.asObservable()}setAllowedElementClassNames(e){try{this.analyticsService.setFeatureConfig({feature:ke.COMMENT,config:{allowedElementClassNames:e}}),this.allowedElementClassNames$.next(e||[])}catch(t){this.loggingService.catch("Error in CommentService setAllowedElementClassNames: ",t)}}getAllowedElementClassNames(){return this.allowedElementClassNames$.asObservable()}setAllowedElementQuerySelectors(e){try{this.analyticsService.setFeatureConfig({feature:ke.COMMENT,config:{allowedElementQuerySelectors:e}}),this.allowedElementQuerySelectors$.next(e||[])}catch(t){this.loggingService.catch("Error in CommentService setAllowedElementQuerySelectors: ",t)}}getAllowedElementQuerySelectors(){return this.allowedElementQuerySelectors$.asObservable()}getAllCommentAnnotations({customClientDocumentId:e,params:t,excludeDomChanges:a,detectGhostComments:i,skipPositionCalculation:c,query:m,fromCommentSidebar:h,analytics:_,addFilterCommentsOnDomCheck:I}){this.loggingService.log("%c[WB] Calling FUNCTION: getAllCommentAnnotations","color: green;");let S,z,$;_?.enabled&&this.analyticsService.trackEvent(_?.eventName||ne.Events.Comments.GET_ALL_COMMENT_ANNOTATIONS_TRIGGERED_INTERNAL,_?.properties);try{if(e&&($=`${wo(e)}`),t&&typeof t=="object"){let G=Nu(t);z=G?.id,S=wo(JSON.stringify(G))}}catch(G){this.loggingService.catch("Error in CommentService getAllCommentAnnotations: ",G)}return this.authService.getAuthState$().pipe(jt(G=>!!G),Me(G=>this.isFeatureAllowed({firebaseUser:G,annotations:[],filteredAnnotations:[]})),Me(G=>G.featureAllowed?this.iamService.isUserAllowed$().pipe(Oe(Z=>(G.featureAllowed=Z,G))):Ee(G)),Me(G=>G.featureAllowed?Ee(G).pipe(Me(Z=>this.docService.getDocumentPaths$().pipe(Oe(ae=>(this.documentPaths=ae,Z.documentPaths=ae,Z)))),Me(Z=>m?.documentIds?.length||$?this.getDataFromDocumentIds({documentIds:$?[$]:m?.documentIds?.map(ae=>`${wo(ae)}`),organizationId:this.documentPaths?.organizationId,query:m}).pipe(Oe(ae=>({res:Z,data:ae}))):this.docService.getDocumentIds$().pipe(Me(ae=>{let pe=ae?.length>0?ae.map(Se=>Se.documentId):[this.documentPaths?.documentId??""];return this.getDataFromDocumentIds({documentIds:pe.length>0?pe:[$??""],organizationId:this.documentPaths?.organizationId,query:m}).pipe(Oe(Se=>({res:Z,data:Se})))}))),Me(Z=>Z?.data?(Z.res.annotations=Z.data||[],Ee(Z.res).pipe(Me(ae=>this.docService.getLocation$().pipe(Oe(pe=>(ae.location=pe,ae)))),Me(ae=>this.docService.getLocations$().pipe(Oe(pe=>(ae.customLocations=pe,ae)))),Me(ae=>this.docService.getExcludedLocationIds$().pipe(Oe(pe=>(ae.excludedLocationIds=pe,ae)))),Oe(ae=>{if(ae.filteredAnnotations=[],m)return ae.filteredAnnotations=ae.annotations?.slice(),ae;if($&&!S||h)return ae.filteredAnnotations=ae.annotations?.slice(),ae?.excludedLocationIds?.length&&(ae.filteredAnnotations=ae.filteredAnnotations?.filter(pe=>pe?.location?.id?!ae.excludedLocationIds.includes(pe.location.id):!0)),ae;{let pe=[],Se=[];return S?(pe.push(S),z&&Se.push(z)):(pe.push(ae?.location?.locationId),pe.push(...Object.values(ae?.customLocations||[]).map(oe=>oe.locationId)),ae?.location?.location?.id&&Se.push(ae?.location?.location?.id),Se.push(...Object.values(ae?.customLocations||{}).map(oe=>oe.location?.id).filter(oe=>!!oe))),ae.filteredAnnotations=this.filterAnnotationsByLocationIds(ae?.annotations,pe,Se),ae?.excludedLocationIds?.length&&(ae.filteredAnnotations=ae.filteredAnnotations?.filter(oe=>oe?.location?.id?!ae.excludedLocationIds.includes(oe.location.id):!0)),ae}}),Me(ae=>this.isPrivateCommentAllowed$().pipe(Oe(pe=>(pe||(ae.filteredAnnotations=ae.filteredAnnotations?.filter(Se=>!sr(Se))),ae)))),Me(ae=>this.draftCommentAnnotationsByAnnotationId$.pipe(Oe(pe=>(ae.filteredAnnotations=ae.filteredAnnotations?.filter(Se=>!Se.isDraft),pe&&ae.filteredAnnotations.push(...Object.values(pe)),ae)))),Me(ae=>a?Ee(ae):ae?.annotations?.length&&(!this.getPopoverMode()||this.getPopoverTriangleComponent())?this.domService.onWindowResize$().pipe(Oe(()=>ae)):Ee(ae)),Me(ae=>a?Ee(ae):this.addCommentMode$.pipe(Me(pe=>pe&&!this.getChangeDetectionInCommentMode()?Ee(ae):ae?.annotations?.length&&(!this.getPopoverMode()||this.getPopoverTriangleComponent())?this.domService.onDomChange$("CommentService getAllCommentAnnotations").pipe(Oe(()=>ae)):Ee(ae)))),Oe(ae=>{if(!c){(!this.getPopoverMode()||this.getPopoverTriangleComponent())&&(ae.filteredAnnotations=ae.filteredAnnotations?.map(Se=>{let oe=Object.assign({},Se);return this.calculateCommentAnnotationPosition(oe,i),oe}));let pe={};ae.filteredAnnotations?.forEach(Se=>{if(Se?.targetTextRange){let oe=this.domService.getElementFromTargetTextRange(Se?.targetTextRange);pe[Se.annotationId]=!!oe}}),ae.textAnnotationsElementMap=pe}return ae}),Me(ae=>ae?.annotations?.length?this.serviceBook.observe(Do).pipe(Me(pe=>pe?pe.getCommentFeatureViews$():Ee({})),Oe(pe=>(this.updateUnreadAnnotationsMap(ae?.annotations,pe),ae))):(Ty(this.unreadCommentsMap$.value)&&this.unreadCommentsMap$.next({}),Ee(ae))))):Ee(null))):Ee(null)),Oe(G=>{try{return typeof G=="object"&&G?JSON.parse(JSON.stringify(G)):G}catch{return G}}),gr((G,Z)=>Wr(G?.filteredAnnotations,Z?.filteredAnnotations)&&Wr(G?.textAnnotationsElementMap,Z?.textAnnotationsElementMap)),Me(G=>G?G?.filteredAnnotations?Ee(G?.filteredAnnotations||[]):Ee([]):Ee(null)),Me(G=>I?this.filterCommentsUsingSidebarSettings(G):Ee(G)))}getAllMultiThreadCommentAnnotations(e,t,a,i,c,m){this.loggingService.log("%c[WB] Calling FUNCTION: getAllMultiThreadCommentAnnotations","color: green;");let h,_;try{if(e&&(_=wo(e)),t&&typeof t=="object"){let I=Nu(t);h=wo(JSON.stringify(I))}}catch(I){this.loggingService.catch("Error in CommentService getAllMultiThreadCommentAnnotations: ",I)}return this.authService.getAuthState$().pipe(jt(I=>!!I),Me(I=>this.isFeatureAllowed({firebaseUser:I,annotations:[],filteredAnnotations:[]})),Me(I=>I.featureAllowed?this.iamService.isUserAllowed$().pipe(Oe(S=>(I.featureAllowed=S,I))):Ee(I)),Me(I=>I.featureAllowed?Ee(I).pipe(Me(S=>this.docService.getDocumentPaths$().pipe(Oe(z=>(this.documentPaths=z,S.documentPaths=z,S)))),Me(S=>_?this.getMultiThreadDataFromDocumentIds([_]).pipe(Oe(z=>({res:S,data:z}))):this.docService.getDocumentIds$().pipe(Me(z=>{let $=z?.length>0?z.map(G=>G.documentId):[this.documentPaths?.documentId??""];return this.getMultiThreadDataFromDocumentIds($.length>0?$:[`${_}`]).pipe(Oe(G=>({res:S,data:G})))}))),Me(({res:S,data:z})=>z?(S.annotations=z||[],Ee(S).pipe(Me($=>this.docService.getLocation$().pipe(Oe(G=>($.location=G,$)))),Me($=>this.docService.getLocations$().pipe(Oe(G=>($.customLocations=G,$)))),Me($=>this.docService.getExcludedLocationIds$().pipe(Oe(G=>($.excludedLocationIds=G,$)))),Oe($=>{if($.filteredAnnotations=[],_&&!h)return $.filteredAnnotations=$.annotations?.slice(),$?.excludedLocationIds?.length&&($.filteredAnnotations=$.filteredAnnotations?.filter(G=>G?.location?.id?!$.excludedLocationIds.includes(G.location.id):!0)),$;{let G=[],Z=[];return h?G.push(h):(G.push($?.location?.locationId),G.push(...Object.values($?.customLocations||[]).map(ae=>ae.locationId)),$?.location?.location?.id&&Z.push($?.location?.location?.id),Z.push(...Object.values($?.customLocations||{}).map(ae=>ae.location?.id).filter(ae=>!!ae))),$.filteredAnnotations=this.filterAnnotationsByLocationIds($?.annotations,G,Z),$?.excludedLocationIds?.length&&($.filteredAnnotations=$.filteredAnnotations?.filter(ae=>ae?.location?.id?!$.excludedLocationIds.includes(ae.location.id):!0)),$}}),Me($=>this.draftMultiThreadCommentAnnotationsByAnnotationId$.pipe(Oe(G=>($.filteredAnnotations=$.filteredAnnotations?.filter(Z=>!Z.isDraft),G&&$.filteredAnnotations.push(...Object.values(G)),$)))),Me($=>a?Ee($):$?.annotations?.length&&(!this.getPopoverMode()||this.getPopoverTriangleComponent())?this.domService.onWindowResize$().pipe(Oe(()=>$)):Ee($)),Me($=>a?Ee($):this.addCommentMode$.pipe(Me(G=>G&&!this.getChangeDetectionInCommentMode()?Ee($):$?.annotations?.length&&(!this.getPopoverMode()||this.getPopoverTriangleComponent())?this.domService.onDomChange$("CommentService getAllMultiThreadCommentAnnotations").pipe(Oe(()=>$)):Ee($)))),Oe($=>(c||(!this.getPopoverMode()||this.getPopoverTriangleComponent())&&($.filteredAnnotations=$.filteredAnnotations?.map(G=>{let Z=Object.assign({},G);return this.calculateCommentAnnotationPosition(Z,i),Z})),$)),Me($=>$?.filteredAnnotations?Ee($?.filteredAnnotations||[]):Ee([])))):Ee(null))):Ee(null)),gr(Wr),Me(I=>m?this.filterCommentsUsingSidebarSettings(I):Ee(I)))}isFeatureAllowed(e){return this.configService.getConfig$().pipe(jt(t=>!!t),Oe(t=>f(g({},e),{config:t})),Me(t=>this.authService.getUser$().pipe(Oe(a=>(this.user=a,f(g({},t),{user:a}))))),Me(t=>Zh(t.config,t.user,ke.COMMENT)?Ee(f(g({},t),{featureAllowed:!0})):(this.loggingService.warn("Comment feature is not allowed."),Ee(f(g({},t),{featureAllowed:!1})))),gr((t,a)=>t?.featureAllowed===a?.featureAllowed))}buildVisibilityTokens(e){return Pe(this,null,function*(){try{let a=this.authService.getUser()?.clientOrganizationId,i=a?yield this.isViewerOrgMembershipConfirmed(e,a):!1;return Fu({userId:e,clientOrganizationId:i?a:void 0,fallbackServerOrganizationId:a?void 0:this.documentPaths?.organizationId})}catch(t){this.loggingService.catch("Error in CommentService buildVisibilityTokens: ",t);try{return[X.DEFAULT_VELT_CONTEXT,`${X.VISIBILITY_SELF_PREFIX}${mr(e)}`]}catch{return[X.DEFAULT_VELT_CONTEXT]}}})}isViewerOrgMembershipConfirmed(e,t){return Pe(this,null,function*(){try{let i=(yield this.userPermissionService.getUserPermissionsFromCacheOrFetch({organizationId:t}))?.[e]?.organization?.[t];return!!i&&i.errorCode!==kg.PERMISSION_DENIED}catch(a){return this.loggingService.catch("Error in CommentService isViewerOrgMembershipConfirmed: ",a),!1}})}getDataFromDocuments(e){let{documentIds:t,organizationId:a,query:i}=e;if(!this.configService?.getApiKey())return Ee(null);if(t?.some(z=>!z)||!this.documentPaths)return Ee(null);let c,m,h=[];if(i)i?.folderId&&(c=dr(i?.folderId)),i?.locationId&&(h=[...h,i?.locationId]),i?.locationIds?.length&&(h=[...h,...i?.locationIds]),m=i?.statusIds;else{c=this.docService.getDocumentPaths()?.veltFolderId;let z=this.docService.getDocumentPaths()?.locationId;z&&(h=[...h,z])}let _={useCollectionGroup:!0,isCollection:!0,useQuery:!0};this.commonDbService.shouldUseFirestore()||(_.documentId=t?.length?t[0]:void 0,_.organizationId=this.documentPaths?.organizationId);let I=this.authService.getUser()?.userId;if(!I)return Ee(null);let S=this.authService.getIsPrivateCommentsEnabled();return rh(()=>(S?_n(this.buildVisibilityTokens(I)):Ee([X.DEFAULT_VELT_CONTEXT])).pipe(Me($=>{let G=this.userPermissionService?.getIsContextEnabled()?this.docService.getProcessedDocContext():[],Z=[...$,...G],ae=this.userPermissionService?.getIsContextEnabled(),pe;if(ae){let Se=[];for(let oe=0;oe<Z.length;oe+=X.LISTENER_CONTEXT_BATCH_SIZE)Se.push(Z.slice(oe,oe+X.LISTENER_CONTEXT_BATCH_SIZE));this.loggingService.logContext("[CONTEXT] getDataFromDocuments called with accessFields:",JSON.parse(JSON.stringify(Z??"nil"))),pe=kr(Se.map(oe=>this.commonDbService.dbListener({feature:"allComments",properties:f(g({},_),{firestoreQuery:[Mr(Qe("metadata.apiKey","==",this.configService?.getApiKey()),Qe("metadata.organizationId","==",a??this.documentPaths?.organizationId),Qe("metadata.documentId","in",t),...m?.length?[Qe("status.id","in",m)]:[],...c?[Qe("metadata.veltFolderId","==",c)]:[],...h?.length?[Qe("location.id","in",h)]:[],...oe?.length?[Qe("context.accessFields","array-contains-any",oe)]:[]),Xt("lastUpdated","desc"),Xt("createdAt","desc")]})}).pipe(Pc()))).pipe(Oe(oe=>Lc(JSON.parse(JSON.stringify(oe)))))}else{let Se=[];for(let oe=0;oe<(t?.length??0);oe+=X.LISTENER_BATCH_SIZE)Se.push(t?.slice(oe,oe+X.LISTENER_BATCH_SIZE)??[]);pe=kr(Se.map(oe=>this.commonDbService.dbListener({feature:"allComments",properties:f(g({},_),{firestoreQuery:[Mr(Qe("metadata.apiKey","==",this.configService?.getApiKey()),Qe("metadata.organizationId","==",a??this.documentPaths?.organizationId),Qe("metadata.documentId","in",oe),...m?.length?[Qe("status.id","in",m)]:[],...c?[Qe("metadata.veltFolderId","==",c)]:[],...h?.length?[Qe("location.id","in",h)]:[],...Z?.length&&S?[Qe("context.accessFields","array-contains-any",Z)]:[]),Xt("lastUpdated","desc"),Xt("createdAt","desc")]})}).pipe(Pc()))).pipe(Oe(oe=>Lc(JSON.parse(JSON.stringify(oe)))))}return pe.pipe(Me(Se=>Se?.data?Ee(Se).pipe(Me(oe=>this.commonDbUtilsService.mergeLocationMetadataWithData$({data:oe,feature:"allComments"}).pipe(Oe(he=>({data:Object.values(he?.data||{}).filter(_e=>typeof _e=="object"),operation:he?.operation})))),Oe(({data:oe,operation:he})=>{let _e=oe.reduce((Re,Ye)=>{let lt=Ye.metadata?.documentId;return lt&&(Re[lt]||(Re[lt]=[]),Re[lt].push(Ye)),Re},{});return{data:oe,documentMap:_e,operation:he}}),Oe(({data:oe,documentMap:he,operation:_e})=>m?{data:oe,documentMap:he,operation:_e}:(oe?.length&&(oe?.forEach(Re=>{this.sanitizeCommentAnnotation(Re)}),this.setAnnotationIndex(oe),this.updateAnnotationsForSelectAllContentMode(oe),oe.forEach(Re=>{this.customFilterService.convertLegacyAnnotationStatus(Re),this.customFilterService.convertLegacyPriority(Re),this.customFilterService.convertLegacyCategory(Re)})),{data:oe,documentMap:he,operation:_e})),yn(oe=>(this.loggingService.catch("Error in CommentService getDataFromDocuments: ",oe),Ee([]))),Ac(({documentMap:oe})=>{m||Object.entries(oe??{}).forEach(([he,_e])=>{this.setOriginalCommentAnnotationsByAnnotationId(JSON.parse(JSON.stringify(_e)))})}),Oe(({data:oe,documentMap:he,operation:_e})=>({data:this.filterUserDraftComments(oe),documentMap:he,operation:_e})),Oe(({data:oe,documentMap:he,operation:_e})=>({data:this.removeDraftFlags(oe),documentMap:he,operation:_e})),Me(({data:oe,documentMap:he,operation:_e})=>m?Ee({data:oe,documentMap:he,operation:_e}):this.mergeDraftAnnotations(oe).pipe(Oe(Re=>({data:Re,documentMap:he,operation:_e})))),Oe(({data:oe,documentMap:he,operation:_e})=>{if(!m)if(_e?.type==="removed"){if(_e?.ids?.length){let Re=this.commentAnnotationById$.value??{};_e?.ids?.forEach(Ye=>{delete Re?.[Ye]}),this.commentAnnotationById$.next(Re)}}else Object.entries(he??{}).length?Object.entries(he??{}).forEach(([Ye,lt])=>{this.setCommentAnnotationsByOrganizationIdAndDocumentId({organizationId:this.documentPaths?.organizationId,documentId:Ye,annotations:lt})}):this.commentAnnotationById$.value||this.commentAnnotationById$.next({});return oe})):Ee(null)))})))}fetchCommentAnnotations(e){return Pe(this,null,function*(){try{let t=this.authService.getUser();if(!t)return this.loggingService.catch("User not found. Ensure Identify method is called.",void 0,void 0,!0),{data:[],hasMore:!1};let a=this.configService?.getApiKey(),i=e?.organizationId??t?.clientOrganizationId,c=Uv(i??""),m=[];e?.allDocuments||(m=e?.documentIds?.map(pe=>xg(pe??""))??this.docService.getDocumentIds()?.map(pe=>pe.documentId));let h=[];if(h.push(Qe("metadata.organizationId","==",c)),h.push(Qe("metadata.apiKey","==",a)),e?.folderId){let pe=dr(e?.folderId);h.push(Qe("metadata.veltFolderId","==",pe))}if(e?.locationId&&h.push(Qe("location.id","==",e?.locationId)),m?.length&&h.push(Qe("metadata.documentId","in",m)),e?.resolvedBy){if(e?.order==="asc")throw new Error("Order by resolvedBy is not supported in ascending order.");h.push(Qe("resolvedByUserId","==",e?.resolvedBy))}if(e?.mentionedUserIds?.length){if(e?.order==="asc")throw new Error("Order by mentionedUserIds is not supported in ascending order.");h.push(Qe("mentionedUserIds","array-contains-any",e?.mentionedUserIds))}if(e?.userIds?.length){if(e?.order==="asc")throw new Error("Order by userIds is not supported in ascending order.");h.push(Qe("from.userId","in",e?.userIds))}if(e?.statusIds?.length){if(e?.order==="asc")throw new Error("Order by status id is not supported in ascending order.");h.push(Qe("status.id","in",e?.statusIds))}let _=new Date().getTime();if(e?.createdAfter&&h.push(Qe("createdAt",">=",e?.createdAfter)),e?.createdBefore&&h.push(Qe("createdAt","<=",e?.createdBefore??_)),e?.updatedAfter&&h.push(Qe("lastUpdated",">=",e?.updatedAfter??_)),e?.updatedBefore&&h.push(Qe("lastUpdated","<=",e?.updatedBefore??_)),h.push(Xt("lastUpdated",e?.order??"desc"),Xt("createdAt",e?.order??"desc")),e?.pageToken){let pe=yield Qh(e?.pageToken??"","veltencrypttoken","veltencrypttoken");h.push(Db(parseInt(pe,10),"lastUpdated"))}let I=e?.pageSize??100;h.push(Ib(I+1));let S=yield this.commonDbService.queryData({feature:"allComments",properties:{useCollectionGroup:!0,isCollection:!0,useQuery:!0,firestoreQuery:h,apiKey:a??"",organizationId:c}}),z=S.length>I;S=S.slice(0,I);let $=S?.reduce((pe,Se)=>(pe[Se?.annotationId]=Se,pe),{});$=yield this.commonDbUtilsService.formatResponse({feature:"allComments",data:$,shouldAwait:!0}),$=this.commonDbUtilsService.mergeUsersWithData({feature:"allComments",data:$});let G=t.clientOrganizationId?yield this.isViewerOrgMembershipConfirmed(t.userId,t.clientOrganizationId):!1,Z=Fu({userId:t.userId,clientOrganizationId:G?t.clientOrganizationId:void 0,fallbackServerOrganizationId:t.clientOrganizationId?void 0:c});return{data:Kh(Object.values($??{}),{userId:t.userId,tokens:Z}),hasMore:z}}catch(t){throw this.loggingService.catch("Error in CommentService fetchCommentAnnotations:",t),t}})}filterUserDraftComments(e){let t=this.authService.getUser();return e.filter(a=>(a.comments=a?.comments?.filter(i=>i?.from?.userId===t?.userId||!i?.isDraft),!!a?.comments?.length))}removeDraftFlags(e){return e.forEach(t=>delete t.isDraft),e}mergeDraftAnnotations(e){return this.draftCommentAnnotationsByAnnotationId$.pipe(Oe(t=>{let a=t||{};return e?.filter(i=>{a?.[i?.annotationId]&&delete a[i?.annotationId]}),a}),Oe(t=>{if(t){let a=e.slice();return a.push(...Object.values(t)),a}return e}))}getDataFromDocumentIds({documentIds:e,organizationId:t,query:a}){return this.getDataFromDocuments({documentIds:e,organizationId:t,query:a})}getMultiTh