@veltdev/sdk-staging 6.0.0-beta.13 → 6.0.0-beta.15

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 (57) hide show
  1. package/app/models/data/config.data.model.d.ts +38 -5
  2. package/app/utils/enums.d.ts +1 -1
  3. package/{chunk-5JIXRA34.js → chunk-54BT4NQJ.js} +1 -1
  4. package/{chunk-N3AV6IGG.js → chunk-5EO5WTC7.js} +1 -1
  5. package/{chunk-Z77RD4H5.js → chunk-5I3MKJ2F.js} +1 -1
  6. package/{chunk-UF2D32ZI.js → chunk-5NMVUDFG.js} +1 -1
  7. package/{chunk-SXYSM6QP.js → chunk-62RN7JJN.js} +1 -1
  8. package/{chunk-JDZOVFS3.js → chunk-6K2VWE4K.js} +1 -1
  9. package/{chunk-SAPJAJDB.js → chunk-6OW5GJ3E.js} +1 -1
  10. package/{chunk-OHH7LESC.js → chunk-7PEWZDFC.js} +1 -1
  11. package/{chunk-YFZUZKVN.js → chunk-APPJN3VX.js} +1 -1
  12. package/{chunk-VMH5N5PO.js → chunk-B7JPRLBQ.js} +1 -1
  13. package/{chunk-TVX75U2C.js → chunk-CZWARF5M.js} +1 -1
  14. package/{chunk-P54MO3GU.js → chunk-ELEMLDFM.js} +1 -1
  15. package/{chunk-SG6UCHMH.js → chunk-EYPJC34Q.js} +1 -1
  16. package/{chunk-3H5W2TGU.js → chunk-HLPJRWIY.js} +1 -1
  17. package/{chunk-55YE7G6I.js → chunk-HNT7HKW3.js} +1 -1
  18. package/{chunk-DUIGMOMV.js → chunk-HPRUJRZF.js} +1 -1
  19. package/{chunk-XM2SXO32.js → chunk-IY3WJ7XZ.js} +1 -1
  20. package/{chunk-MLCIQM44.js → chunk-JAOM3JHX.js} +1 -1
  21. package/{chunk-N2SSZ74J.js → chunk-K5BJ5DAO.js} +1 -1
  22. package/{chunk-YEQZ76RF.js → chunk-KYEMQS6S.js} +1 -1
  23. package/{chunk-GHVMD37V.js → chunk-LHTLQZLP.js} +1 -1
  24. package/{chunk-JXMMR7DC.js → chunk-MRAZ6ENQ.js} +1 -1
  25. package/{chunk-T4D6QD4H.js → chunk-MZ2HKBWF.js} +1 -1
  26. package/{chunk-7MOQQG4Z.js → chunk-NLVNX52N.js} +1 -1
  27. package/chunk-O4F37U67.js +167 -0
  28. package/{chunk-JPM7CIV3.js → chunk-OEYWDDK3.js} +1 -1
  29. package/{chunk-GJ55RHPP.js → chunk-OK5VRMUL.js} +1 -1
  30. package/{chunk-AIQ4EOVH.js → chunk-POME7PZR.js} +1 -1
  31. package/{chunk-OWD3J56P.js → chunk-RD2BRSWO.js} +1 -1
  32. package/{chunk-GNMKNWD5.js → chunk-S4APJ64C.js} +1 -1
  33. package/{chunk-Q2QL77LS.js → chunk-TMYAQS7C.js} +1 -1
  34. package/{chunk-XM56PHBZ.js → chunk-WJFVURTP.js} +1 -1
  35. package/{chunk-CZTTDJFW.js → chunk-XYR7TNZL.js} +1 -1
  36. package/package.json +1 -1
  37. package/velt-activity-log.js +1 -1
  38. package/velt-area.js +1 -1
  39. package/velt-arrow.js +1 -1
  40. package/velt-comment.js +1 -1
  41. package/velt-crdt.js +1 -1
  42. package/velt-cursor.js +1 -1
  43. package/velt-huddle.js +1 -1
  44. package/velt-live-state-sync.js +1 -1
  45. package/velt-notification.js +1 -1
  46. package/velt-presence.js +1 -1
  47. package/velt-reaction.js +1 -1
  48. package/velt-recorder.js +1 -1
  49. package/velt-rewriter.js +1 -1
  50. package/velt-selection.js +1 -1
  51. package/velt-tag.js +1 -1
  52. package/velt-user-invite.js +1 -1
  53. package/velt-user-request.js +1 -1
  54. package/velt-video-player.js +1 -1
  55. package/velt-views.js +1 -1
  56. package/velt.js +2 -2
  57. package/chunk-NFOSJ24G.js +0 -167
@@ -1,2 +1,2 @@
1
- import{a as Qt}from"./chunk-55YE7G6I.js";import{t as Jt}from"./chunk-N3AV6IGG.js";import"./chunk-P54MO3GU.js";import"./chunk-JDZOVFS3.js";import{a as Ht}from"./chunk-YFZUZKVN.js";import"./chunk-SG6UCHMH.js";import{A as W,B as V,y as Vt}from"./chunk-CZTTDJFW.js";import{a as Wt}from"./chunk-7MOQQG4Z.js";import{b as re}from"./chunk-GNMKNWD5.js";import{a as Kt}from"./chunk-5JIXRA34.js";import{a as zt}from"./chunk-SXYSM6QP.js";import{a as Mt}from"./chunk-AIQ4EOVH.js";import{da as U,ea as tt,fa as te,ga as it}from"./chunk-N2SSZ74J.js";import{$ as Ae,$f as pe,$h as kt,Bf as Ie,Ch as wt,Dd as Lt,De as ee,Di as Bt,E as k,Fa as h,G as Be,Gc as B,Gi as jt,Hi as Gt,I as je,Ib as at,J as Te,Kb as Tt,L as ne,Lc as Dt,M as Et,Mf as lt,Nb as X,Nf as Qe,Pa as E,Pb as Z,Pc as Ot,Q as ft,Se as ze,T as y,Ta as _t,Te as xt,Ua as q,Va as It,W as Ge,Ya as $,Yf as Rt,_a as S,_b as He,a as f,aa as Ct,ae as Je,ai as Ye,b as A,bc as x,be as Se,bf as Ut,bh as Nt,bi as Xe,ca as L,cc as j,cf as Ke,ch as Pt,ci as c,di as Ft,fc as G,g as Q,ha as le,i as mt,ia as de,ih as Ee,ii as Ze,k as ot,kc as J,ki as De,l as Y,lb as v,lc as z,li as Oe,mb as R,nb as N,ne as ct,ob as Ve,p as st,pc as At,qa as We,qh as ae,r as p,sb as b,si as qt,t as ht,tb as _,u as St,ua as bt,ub as yt,uh as m,v as D,vb as ge,w as pt,wa as F,xb as ue,xi as $t,yi as et,z as Le,zb as g,ze as K}from"./chunk-NFOSJ24G.js";var nt=(()=>{let r=class r{constructor(e,t){this.analyticsService=e,this.loggingService=t,this.actionSubjects=new Map,this.subscriptions=[]}onAccessRequested(e){try{this.triggerAction(Se.ACCESS_REQUESTED,e),this.analyticsService.trackEvent(m.Events.LiveStateSync.SEM_ACCESS_REQUESTED,{viewerUserId:e?.viewer?.userId,editorUserId:e?.editor?.userId,timestamp:e?.timestamp,status:e?.status,totalUsers:e?.totalUsers,isMultipleUsersDetected:(e?.totalUsers??0)>1,presenceSnippylyUserIds:e?.presenceSnippylyUserIds,presenceClientUserIds:e?.presenceClientUserIds})}catch(t){this.loggingService.catch("Error in LiveStateActionsService onAccessRequested: ",t)}}onAccessRequestCanceled(e){try{this.triggerAction(Se.ACCESS_REQUEST_CANCELED,e),this.analyticsService.trackEvent(m.Events.LiveStateSync.SEM_ACCESS_REQUEST_CANCELED,{viewerUserId:e?.viewer?.userId,editorUserId:e?.editor?.userId,timestamp:e?.timestamp,status:e?.status,totalUsers:e?.totalUsers,isMultipleUsersDetected:(e?.totalUsers??0)>1,presenceSnippylyUserIds:e?.presenceSnippylyUserIds,presenceClientUserIds:e?.presenceClientUserIds})}catch(t){this.loggingService.catch("Error in LiveStateActionsService onAccessRequestCanceled: ",t)}}onAccessAccepted(e){try{this.triggerAction(Se.ACCESS_ACCEPTED,e),this.analyticsService.trackEvent(m.Events.LiveStateSync.SEM_ACCESS_ACCEPTED,{viewerUserId:e?.viewer?.userId,editorUserId:e?.editor?.userId,timestamp:e?.timestamp,status:e?.status,totalUsers:e?.totalUsers,isMultipleUsersDetected:(e?.totalUsers??0)>1,presenceSnippylyUserIds:e?.presenceSnippylyUserIds,presenceClientUserIds:e?.presenceClientUserIds})}catch(t){this.loggingService.catch("Error in LiveStateActionsService onAccessAccepted: ",t)}}onAccessRejected(e){try{this.triggerAction(Se.ACCESS_REJECTED,e),this.analyticsService.trackEvent(m.Events.LiveStateSync.SEM_ACCESS_REJECTED,{viewerUserId:e?.viewer?.userId,editorUserId:e?.editor?.userId,timestamp:e?.timestamp,status:e?.status,totalUsers:e?.totalUsers,isMultipleUsersDetected:(e?.totalUsers??0)>1,presenceSnippylyUserIds:e?.presenceSnippylyUserIds,presenceClientUserIds:e?.presenceClientUserIds})}catch(t){this.loggingService.catch("Error in LiveStateActionsService onAccessRejected: ",t)}}onEditorAssigned(e){try{this.triggerAction(Se.EDITOR_ASSIGNED,e),this.analyticsService.trackEvent(m.Events.LiveStateSync.SEM_EDITOR_ASSIGNED,{editorUserId:e?.editor?.userId,timestamp:e?.timestamp,role:e?.role,totalUsers:e?.totalUsers,isMultipleUsersDetected:(e?.totalUsers??0)>1,presenceSnippylyUserIds:e?.presenceSnippylyUserIds,presenceClientUserIds:e?.presenceClientUserIds})}catch(t){this.loggingService.catch("Error in LiveStateActionsService onEditorAssigned: ",t)}}onEditorOnDifferentTabDetected(e){try{this.triggerAction(Se.EDITOR_ON_DIFFERENT_TAB_DETECTED,e),this.analyticsService.trackEvent(m.Events.LiveStateSync.SEM_EDITOR_ON_DIFFERENT_TAB_DETECTED,{editorUserId:e?.editor?.userId,timestamp:e?.timestamp,role:e?.role,totalUsers:e?.totalUsers,isMultipleUsersDetected:(e?.totalUsers??0)>1,presenceSnippylyUserIds:e?.presenceSnippylyUserIds,presenceClientUserIds:e?.presenceClientUserIds})}catch(t){this.loggingService.catch("Error in LiveStateActionsService onEditorOnDifferentTabDetected: ",t)}}onViewerAssigned(e){try{this.triggerAction(Se.VIEWER_ASSIGNED,e),this.analyticsService.trackEvent(m.Events.LiveStateSync.SEM_VIEWER_ASSIGNED,{viewerUserId:e?.viewer?.userId,timestamp:e?.timestamp,role:e?.role,totalUsers:e?.totalUsers,isMultipleUsersDetected:(e?.totalUsers??0)>1,presenceSnippylyUserIds:e?.presenceSnippylyUserIds,presenceClientUserIds:e?.presenceClientUserIds})}catch(t){this.loggingService.catch("Error in LiveStateActionsService onViewerAssigned: ",t)}}triggerAction(e,t){try{this.actionSubjects.has(e)||this.actionSubjects.set(e,new ot),this.actionSubjects.get(e)?.next(t)}catch(i){this.loggingService.catch("Error in LiveStateActionsService triggerAction: ",i)}}onAction(e){try{return this.actionSubjects.has(e)||this.actionSubjects.set(e,new ot),this.actionSubjects.get(e)?.asObservable()}catch(t){return this.loggingService.catch("Error in LiveStateActionsService onAction: ",t),p(null)}}};r.\u0275fac=function(t){return new(t||r)(L(Xe),L(c))},r.\u0275prov=Ae({token:r,factory:r.\u0275fac,providedIn:"root"});let n=r;return n})();var Zt=(()=>{let r=class r{constructor(e,t,i,s,l){this.authService=e,this.coreActionsService=t,this.domService=i,this.loggingService=s,this.usersService=l}findOldestActiveSessionFromHeartbeats(e){try{if(!e||e.length===0)return null;let t=this.authService.getUser(),i=this.domService.getTabId(),s=e.filter(d=>d.lastUpdatedTimestamp>Date.now()-1e4);return s.length===0?null:[...s].sort((d,a)=>d.createdTimestamp-a.createdTimestamp)[0]??null}catch(t){return this.loggingService.catch("Error in findOldestActiveSessionFromHeartbeats: ",t),null}}determineEditorStatus(e){return Q(this,null,function*(){try{let{singleEditorModeData:t,heartbeatData:i,externalUserPresence:s,currentUser:l,currentTabId:u}=e,d=JSON.parse(JSON.stringify(t||{})),a={steps:[],timestamp:Date.now()},C=()=>Q(this,null,function*(){let ie=s?.userIds?.[0],se;if(ie){let ke=Qe(),Fe=xt.GET_SINGLE_EDITOR_USERS;this.coreActionsService.triggerAction(Je.USER_RESOLVER,{event:m.Events.Resolver.USER_RESOLUTION_REQUEST_FORMED,timestamp:new Date().getTime(),uniqueId:ke,moduleName:Fe,methodName:ze.SET_SINGLE_EDITOR_MODE_LIVE_STATE_DATA_FOR_DIFFERENT_USER_PRESENT_ON_TAB,source:"internal",payload:{userIds:[ie],forceResolve:!0}}),yield this.usersService.resolveUsers({userIds:[ie],forceResolve:!0,uniqueId:ke,moduleName:Fe}),se=this.usersService.getUserById(ie)}se?(d.editor=se,d.tabId=`differentUserPresentOnTab_${u}`):(d.editor={userId:`anonymous_${l?.userId}`,name:"Anonymous"},d.tabId=`differentUserPresentOnTab_${u}`)}),P=()=>{d.editor=l,d.tabId=`sameUserPresentOnTab_${u}`},O=!1;if(t?.editor){if(a.steps?.push("SingleEditorModeData: Editor is available."),i?.length){a.steps?.push("Heartbeat data is available.");let ie=i?.find(se=>se.userId===t?.editor?.userId&&se.tabId===t?.tabId);if(ie&&ie.lastUpdatedTimestamp>Date.now()-1e4)a.steps?.push("Editor user heartbeat is recent.");else{a.steps?.push("Editor user heartbeat is not available or not recent.");let se=this.findOldestActiveSessionFromHeartbeats(i);se&&se.userId===l.userId&&se.tabId===u?(a.steps?.push("Current user is the oldest active session."),O=!0):a.steps?.push("Current user is not the oldest active session.")}}!i?.length&&!s&&a.steps?.push("No heartbeat data and no external user presence is available.")}else{if(a.steps?.push("SingleEditorModeData: Editor not available."),i?.length){a.steps?.push("Heartbeat data is available.");let ie=this.findOldestActiveSessionFromHeartbeats(i);ie&&ie.userId===l.userId&&ie.tabId===u?(a.steps?.push("Current user is the oldest active session."),O=!0):a.steps?.push("Current user is not the oldest active session.")}else s&&(a.steps?.push("External user presence is available."),s.differentUserPresentOnTab?(a.steps?.push("External user presence: Different user is present on the tab."),yield C(),O=!1):s.sameUserPresentOnTab?(a.steps?.push("External user presence: Same user is present on the tab."),P(),O=!1):(a.steps?.push("External user presence: No user is present on the tab."),O=!0));!i?.length&&!s&&(a.steps?.push("No heartbeat data and no external user presence is available."),O=!0)}let w;return O?w={shouldSetUndefined:!0}:w={data:d},a.singleEditorModeData=t,a.singleEditorModeDataEditorAvailable=!!t?.editor,a.heartbeatData=i,a.externalUserPresence=s,a.currentUser=l,a.currentTabId=u,a.returnValue=w,a.shouldSetUndefined=O,a.steps?.push("Execution completed."),a=this.cleanStats(a),A(f({},w),{stats:a})}catch(t){return this.loggingService.catch("Error in determineEditorStatus: ",t),{data:e?.singleEditorModeData??void 0}}})}cleanStats(e){try{let t=e&&typeof e=="object"?JSON.parse(JSON.stringify(e)):e;return t?.singleEditorModeData?.editor&&(t.singleEditorModeData=A(f({},t.singleEditorModeData),{editor:{userId:t.singleEditorModeData?.editor?.userId}})),t?.returnValue?.data?.editor&&(t.returnValue.data=A(f({},t.returnValue.data),{editor:{userId:t.returnValue.data?.editor?.userId}})),t}catch{return e}}};r.\u0275fac=function(t){return new(t||r)(L(Oe),L(Ze),L(De),L(c),L(et))},r.\u0275prov=Ae({token:r,factory:r.\u0275fac,providedIn:"root"});let n=r;return n})();var T=(()=>{let r=class r{constructor(e,t,i,s,l,u,d,a,C,P,O,w,ie,se,ke,Fe,ui,vi){this.afAuth=e,this.analyticsService=t,this.authService=i,this.configService=s,this.coreActionsService=l,this.databaseService=u,this.docService=d,this.domService=a,this.heartbeatService=C,this.iamService=P,this.loggingService=O,this.commonDbService=w,this.liveStateActionsService=ie,this.liveStateUtilsService=se,this.usersService=ke,this.singleEditorDecisionEngine=Fe,this.serviceBook=ui,this.realtimeAdapter=vi,this.db=null,this.liveStateAutoSyncStateData$=new Y(null),this.liveStateDataMapDraft={},this.singleEditorMode$=new Y(!1),this.singleEditorModeConfig$=new Y(null),this.singleEditorLiveStateData$=new Y(null),this.singleEditorLiveStateData={},this.editorAccessTimeout$=new Y(ee.LIVE_STATE_REQUEST_EDITOR_ACCESS_WAIT_TIME),this.editorAccessTransferOnTimeOut$=new Y(!0),this.defaultSingleEditorUIEnabled$=new Y(!0),this.editorAccessTimer$=new Y(new Ke),this.autoSyncState$=new Y(!1),this.serverConnectionState$=new Y(K.PENDING_INIT),this.externalUserPresence$=new Y(null),this.heartbeat$=new Y(!0),this.user=null,this.keydownSubscription=null,this.isEditor$=new Y(null),this.preventEventsOnElementMap={},this.PREVENT_EVENTS=["click","mouseup","mousedown"],this.autoSyncStateHistory=null,this.singleEditorModeContainerIds$=new Y([]),this.inputChangeSubscriptionMap={},this.childListMutationSubscription=null,this.tabId=this.domService.getTabId(),this.heartbeatRestart$=new Y(void 0),this.connectionListenerUnsubscribe=null,this.offlineTimer=null;try{this.loggingService.log("%c[WB] Creating CLASS: LiveStateService","color: blue;"),pt([this.getSingleEditorMode$(),this.heartbeat$]).subscribe(([I,M])=>{I&&M?this.heartbeatService.enableHeartbeat():this.heartbeatService.disableHeartbeat()}),this.databaseService.getDb().pipe(k(I=>!!I),Te(1)).subscribe(I=>{I&&(this.db=I,this.getUser(),this.getDocumentPaths(),this.subscribeLiveStateData().subscribe(),this.subscribeAutoSyncState().subscribe(),this.singleEditorMode$.subscribe(M=>{M&&this.detectKeydownOnInput()}),this.autoSyncState$.subscribe(M=>{M?(this.detectLiveSyncInputs(),this.observeElementAddedOnDom()):(this.unsubscribeInputChanges(),this.childListMutationSubscription?.unsubscribe(),this.childListMutationSubscription=null)}),this.updateOnDatabaseDisconnect().subscribe(()=>{},M=>{this.loggingService.catch("Error in LiveStateService constructor updateOnDatabaseDisconnect: ",M)}),this.updateServerStateOnDatabaseDisconnect().subscribe(()=>{},M=>{this.loggingService.catch("Error in LiveStateService constructor updateServerStateOnDatabaseDisconnect: ",M)}))},I=>{this.loggingService.catch("Error in LiveStateService getDb subscription: ",I)}),this.liveStateAutoSyncStateData$.pipe(k(I=>Object.keys(I||{}).length>0),ne((I,M)=>JSON.stringify(I||{})===JSON.stringify(M||{}))).subscribe(I=>{I&&(this.getAutoSyncState()&&(!this.autoSyncStateHistory&&I?.history&&this.updateLiveStateSyncInputDataLocally(I.history),I?.current&&this.updateLiveStateSyncInputDataLocally({[I.current.liveStateDataId]:I.current})),!this.autoSyncStateHistory&&I?.history&&(this.autoSyncStateHistory=I.history))}),this.docService.addPreDocumentIdChangeFunction("live-state-service",I=>(this.updateExternalUserPresence(null),this.isUserEditor()?.isEditor&&(!this.getSingleEditorModeConfig()?.singleTabEditor||this.isUserEditor()?.isEditorOnCurrentTab)?this.removeEditorAccess({metadata:{from:"addPreDocumentIdChangeFunction-liveStateService",reason:"Document id changed"},documentPaths:I}):Promise.resolve())),this.authService.addPreSignOutFuction("live-state-signout",this.signOutUser.bind(this)),this.singleEditorLiveStateData$.pipe(Et()).subscribe(([I,M])=>{try{let ve=M?.requestEditorAccess?.status,be=I?.requestEditorAccess?.status,qe=this.authService.getUser(),$e=this.getPresenceData();if(ve==="pending"){if(qe?.userId===M?.editor?.userId){let _e=f({viewer:ae(M?.requestEditorAccess?.user)??void 0,editor:ae(M?.editor)??void 0,timestamp:new Date().getTime(),status:"requested"},$e);this.liveStateActionsService?.onAccessRequested(_e)}return}if(ve==="cancelled"){if(qe?.userId===M?.editor?.userId){let _e=f({viewer:ae(M?.requestEditorAccess?.user)??void 0,editor:ae(M?.editor)??void 0,timestamp:new Date().getTime(),status:"canceled"},$e);this.liveStateActionsService?.onAccessRequestCanceled(_e)}return}if(be==="pending"&&!ve){if(I?.requestEditorAccess?.user?.userId===M?.editor?.userId){if(I?.requestEditorAccess?.user?.userId===qe?.userId){let _e=f({viewer:ae(I?.editor)??void 0,editor:ae(M?.editor)??void 0,timestamp:new Date().getTime(),status:"accepted"},$e);this.liveStateActionsService?.onAccessAccepted(_e)}return}if(I?.requestEditorAccess?.user?.userId!==M?.editor?.userId){if(I?.requestEditorAccess?.user?.userId===qe?.userId){let _e=f({viewer:ae(I?.requestEditorAccess?.user)??void 0,editor:ae(M?.editor)??void 0,timestamp:new Date().getTime(),status:"rejected"},$e);this.liveStateActionsService?.onAccessRejected(_e)}return}}}catch(ve){this.loggingService.catch("Error in LiveStateService singleEditorLiveStateData$ subscription: ",ve)}}),this.isUserEditor$().pipe(ne(Ee)).subscribe(I=>{try{if(I){this.analyticsService.trackEvent(m.Events.LiveStateSync.SEM_USER_EDITOR_STATS,{isEditor:I?.isEditor,isEditorOnCurrentTab:I?.isEditorOnCurrentTab});let M=this.singleEditorLiveStateData$.value,ve=this.getPresenceData();if(I?.isEditor)if(I?.isEditorOnCurrentTab){let be=f({editor:ae(M?.editor)??void 0,timestamp:new Date().getTime(),role:"editor"},ve);this.liveStateActionsService?.onEditorAssigned(be)}else{let be=f({editor:ae(M?.editor)??void 0,timestamp:new Date().getTime(),role:"editorOnDifferentTab"},ve);this.liveStateActionsService?.onEditorOnDifferentTabDetected(be)}else{let be=f({viewer:ae(this.authService.getUser())??void 0,timestamp:new Date().getTime(),role:"viewer"},ve);this.liveStateActionsService?.onViewerAssigned(be)}}}catch(M){this.loggingService.catch("Error in LiveStateService isUserEditor$ subscription: ",M)}})}catch(I){this.loggingService.catch("Error in LiveStateService constructor: ",I)}}getPresenceData(){try{let t=this.serviceBook.get(wt)?.getPresenceUsers();return{totalUsers:t?.length,presenceSnippylyUserIds:t?.map(i=>i.userSnippylyId).filter(i=>!!i),presenceClientUserIds:t?.map(i=>i.userId)}}catch(e){return this.loggingService.catch("Error in LiveStateService getPresenceData: ",e),{}}}observeElementAddedOnDom(){try{this.loggingService.log("%c[WB] Calling FUNCTION: observeElementAddedOnDom","color: green;"),this.childListMutationSubscription&&(this.childListMutationSubscription.unsubscribe(),this.childListMutationSubscription=null),this.childListMutationSubscription=this.domService.getChildListMutation$().subscribe(e=>{e?.length&&e.forEach(t=>{let i=Array.from(t.addedNodes||[]).filter(s=>s instanceof HTMLElement);i?.forEach(s=>{Nt(s,!0)?.forEach(d=>{typeof d?.getAttribute=="function"&&d?.getAttribute(ee.ATTRIBUTES.VELT_SYNC_STATE)&&this.subscribeInputChanges(d)})}),i?.length&&this.isEditor$?.value?.isEditor===!1&&(this.disableInputElements(),this.disableElementEvents())})},e=>{this.loggingService.catch("Error in LiveStateService domService getChildListMutation$ subscription: ",e)})}catch(e){this.loggingService.catch("Error in LiveStateService observeElementAddedOnDom: ",e)}}detectKeydownOnInput(){try{this.loggingService.log("%c[WB] Calling FUNCTION: detectKeydownOnInput","color: green;"),this.unsubscribeKeydownSubscription(),this.keydownSubscription=this.domService.onWindowKeydown$().pipe(k(e=>e?.target instanceof HTMLInputElement||e?.target instanceof HTMLTextAreaElement||e?.target instanceof HTMLSelectElement),k(e=>!!this.isElementInsideSingleEditorModeContainerElements(e?.target)),Te(1)).subscribe(e=>{this.unsubscribeKeydownSubscription(),this.getSingleEditorModeConfig()?.customMode||this.setUserAsEditor({skipEditorCheck:!0})},e=>{this.loggingService.catch("Error in LiveStateService detectKeydownOnInput subscription: ",e)})}catch(e){this.loggingService.catch("Error in LiveStateService detectKeydownOnInput: ",e)}}unsubscribeKeydownSubscription(){try{this.loggingService.log("%c[WB] Calling FUNCTION: unsubscribeKeydownSubscription","color: green;"),this.keydownSubscription&&(this.keydownSubscription.unsubscribe(),this.keydownSubscription=null)}catch(e){this.loggingService.catch("Error in LiveStateService unsubscribeKeydownSubscription: ",e)}}getDocumentPaths(){try{this.loggingService.log("%c[WB] Calling FUNCTION: getDocumentPaths","color: green;"),this.docService.getDocumentPaths$().subscribe(e=>{this.documentPaths=e,this.updateLiveStateDataFromDraft()})}catch(e){this.loggingService.catch("Error in LiveStateService getDocumentPaths: ",e)}}getUser(){try{this.loggingService.log("%c[WB] Calling FUNCTION: getUser","color: green;"),this.authService.getUser$().subscribe(e=>{this.user=e,this.updateLiveStateDataFromDraft()})}catch(e){this.loggingService.catch("Error in LiveStateService getUser: ",e)}}updateLiveStateDataFromDraft(){try{this.loggingService.log("%c[WB] Calling FUNCTION: updateLiveStateDataFromDraft","color: green;"),this.liveStateDataMapDraft?.custom&&this.user&&this.documentPaths&&(Object.keys(this.liveStateDataMapDraft.custom).forEach(e=>{this.setLiveStateData(e,this.liveStateDataMapDraft.custom[e])}),this.liveStateDataMapDraft={})}catch(e){this.loggingService.catch("Error in LiveStateService updateLiveStateDataFromDraft: ",e)}}getActiveHeartbeatStream$(e){return this.heartbeatRestart$.pipe(Te(50),y(()=>{let t=this.heartbeatService.getHeartbeatData({documentId:this.documentPaths?.documentId}).pipe(Te(1),y(i=>{let s=this.singleEditorDecisionEngine.findOldestActiveSessionFromHeartbeats(i);return s?this.monitorSession$(s.userId,s.tabId):p(null)}));return!e?.userId||!e?.tabId?t:this.heartbeatService.getSpecificHeartbeat({userId:e.userId,tabId:e.tabId,documentId:this.documentPaths?.documentId}).pipe(Te(1),y(i=>!i?.id||Date.now()-i?.lastUpdatedTimestamp>1e4?t:this.monitorSession$(e.userId,e.tabId)))}),ne((t,i)=>this.isHeartbeatSimilar(t,i)))}monitorSession$(e,t){return this.heartbeatService.getSpecificHeartbeat({userId:e,tabId:t,documentId:this.documentPaths?.documentId}).pipe(y(s=>s?.id?p(s):(this.heartbeatRestart$.next(),st)),St({each:1e4,with:()=>(this.heartbeatRestart$.next(),st)}))}isHeartbeatSimilar(e,t){try{return!e&&!t?!0:!e||!t?!1:e?.userId===t?.userId&&e?.tabId===t?.tabId}catch{return!1}}subscribeLiveStateData(){return this.loggingService.log("%c[WB] Calling FUNCTION: getOnlineUsersOnCurrentDocument","color: green;"),this.authService.getAuthState$().pipe(k(e=>!!e),y(e=>this.isFeatureAllowed({firebaseUser:e,liveStateData:{}})),y(e=>e.featureAllowed?this.iamService.isUserAllowed$().pipe(D(t=>(e.featureAllowed=t,e))):p(e)),y(e=>e.featureAllowed?this.authService.isPlanExpired$().pipe(D(t=>(e.featureAllowed=!t,e))):p(e)),y(e=>e.featureAllowed?p(e).pipe(y(t=>this.docService.getDocumentPaths$().pipe(D(i=>(this.documentPaths=i,t.documentPaths=i,t)))),y(t=>t?.documentPaths?p(t).pipe(Ge(i=>{this.serverConnectionState$?.value===K.PENDING_INIT&&i?.documentPaths?.liveState&&this.serverConnectionState$.next(K.PENDING_DATA)}),y(i=>this.domService.onNetworkStatusChange$().pipe(k(s=>s),D(()=>i))),y(i=>this.getDataFromDocumentId().pipe(D(s=>(i.singleEditorModeData=s,f({},i))))),y(i=>this.getSingleEditorMode$().pipe(D(()=>i))),D(i=>([K.ONLINE,K.OFFLINE].includes(this.serverConnectionState$?.value)||this.serverConnectionState$.next(K.ONLINE),i)),y(i=>this.getSingleEditorMode()?this.getExternalUserPresence$().pipe(D(s=>A(f({},i),{externalUserPresence:s}))):p(i))):p(A(f({},t),{liveStateData:{}}))),y(t=>this.getSingleEditorMode()?this.heartbeatService.getHeartbeatEnabled$().pipe(y(i=>{if(i){let s=t?.singleEditorModeData?.editor,l=t?.singleEditorModeData?.tabId;return this.getActiveHeartbeatStream$({userId:s?.userId,tabId:l}).pipe(D(u=>{let d=u?.id?[u]:null;return A(f({},t),{heartbeatData:d})}))}else return p(A(f({},t),{heartbeatData:null}))})):p(t)),y(t=>{if(this.getSingleEditorMode()){let i=[];if(!(Object.keys(t?.singleEditorModeData||{}).length>0)){let l=this.singleEditorLiveStateData$.value&&typeof this.singleEditorLiveStateData$.value=="object"?JSON.parse(JSON.stringify(this.singleEditorLiveStateData$.value)):this.singleEditorLiveStateData$.value;i.push({eventName:m.Events.LiveStateSync.SEM_SINGLE_EDITOR_LIVE_STATE_EMPTY_DATA_STATS,properties:{previousSingleEditorModeData:l,currentSingleEditorModeData:t?.singleEditorModeData}})}return this.updateSingleEditorLiveSyncData(t?.singleEditorModeData||{},t?.externalUserPresence??null,t?.heartbeatData??null,t,i),p(t)}else return p(t)})):p({})))}updateSingleEditorLiveSyncData(e,t,i,s,l){return Q(this,null,function*(){try{this.loggingService.log("%c[WB] Calling FUNCTION: updateSingleEditorLiveSyncData","color: green;"),pe(e,{})&&!this.keydownSubscription&&this.detectKeydownOnInput();let u=JSON.parse(JSON.stringify(e)),d=yield this.singleEditorDecisionEngine.determineEditorStatus({singleEditorModeData:u,externalUserPresence:t,heartbeatData:i,currentUser:this.authService.getUser(),currentTabId:this.tabId});d?.stats&&l?.push({eventName:m.Events.LiveStateSync.SEM_SINGLE_EDITOR_DETERMINE_EDITOR_STATUS,properties:{stats:d?.stats}});let a;if(this.domService.getNetworkStatus()||(a=null),e=d?.data??{},d?.shouldSetUndefined||(a=null),(s?s?.documentPaths:this.docService.getDocumentPaths())||(a=null),e&&!e?.editor&&this.isEditor$?.value!==a&&this.isEditor$.next(a),pe(this.singleEditorLiveStateData,e))return;{t&&this.compareServerAndExternalData(u,t),l&&l?.length>0&&l.forEach(O=>{O?.eventName&&this.analyticsService.trackEvent(O.eventName,O.properties)}),this.singleEditorLiveStateData=e,this.singleEditorLiveStateData$.next(e);let P;if(this.singleEditorLiveStateData&&typeof this.singleEditorLiveStateData=="object"&&(P=this.liveStateUtilsService.formatLiveStateSingleEditorModeData(JSON.parse(JSON.stringify(this.singleEditorLiveStateData)))),this.analyticsService.trackEvent(m.Events.LiveStateSync.SEM_SINGLE_EDITOR_LIVE_STATE_DATA_STATS,{singleEditorLiveStateData:P}),this.singleEditorLiveStateData?.editor){let O=this.authService.getUser();this.singleEditorLiveStateData?.editor?.userId!==O?.userId?this.makeReader():this.makeEditor()}else this.isEditor$?.value!==a&&this.isEditor$.next(a),this.enableInputElements(),this.enableElementEvents();this.editorAccessTimerInterval&&this.singleEditorLiveStateData?.requestEditorAccess?.status!=="pending"&&this.clearEditorAccessTimerInterval(),this.requestAccessTimer&&this.singleEditorLiveStateData?.requestEditorAccess?.status!=="pending"?this.clearRequestAccessTimer():this.singleEditorLiveStateData?.requestEditorAccess?.status==="pending"&&this.isUserEditor()?.isEditor&&this.isUserEditor()?.isEditorOnCurrentTab&&this.setRequestAccessTimer(this.singleEditorLiveStateData?.requestEditorAccess?.editorAccessTimeout||ee.LIVE_STATE_REQUEST_EDITOR_ACCESS_WAIT_TIME)}}catch{}})}updateSingleEditorLiveSyncDataOld(s,l){return Q(this,arguments,function*(e,t,i=[]){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: updateSingleEditorLiveSyncData","color: green;"),pe(e,{})){let a=yield this.fetchSingleEditorLiveStateDataFromDatabase();if(!pe(a,e)&&(i.push({eventName:m.Events.LiveStateSync.SEM_SINGLE_EDITOR_LIVE_STATE_DATA_MISMATCH,properties:{serverData:a,localData:e}}),a&&typeof a=="object")){let C=yield this.liveStateUtilsService.resolveAndMergeSingleEditorLiveStateDataWithUser(JSON.parse(JSON.stringify(a)));e=JSON.parse(JSON.stringify(C))}}pe(e,{})&&!this.keydownSubscription&&this.detectKeydownOnInput();let u=e&&typeof e=="object"?JSON.parse(JSON.stringify(e)):e;if(t&&(e&&typeof e=="object"&&(e=JSON.parse(JSON.stringify(e))),!e?.editor)){let a=this.authService.getUser();if(t?.sameUserPresentOnTab)e.editor=a,e.tabId=`sameUserPresentOnTab_${this.tabId}`;else if(t?.differentUserPresentOnTab){let C=t?.userIds?.[0],P;if(C){let O=Qe();this.coreActionsService.triggerAction(Je.USER_RESOLVER,{event:m.Events.Resolver.USER_RESOLUTION_REQUEST_FORMED,timestamp:new Date().getTime(),uniqueId:O,methodName:ze.GET_SINGLE_EDITOR_MODE_DATA,source:"internal",payload:{userIds:[C],forceResolve:!0}}),yield this.usersService.resolveUsers({userIds:[C],forceResolve:!0,uniqueId:O}),P=this.usersService.getUserById(C)}P?(e.editor=P,e.tabId=`differentUserPresentOnTab_${this.tabId}`):(e.editor={userId:`anonymous_${a?.userId}`,name:"Anonymous"},e.tabId=`differentUserPresentOnTab_${this.tabId}`)}}let d;if(this.domService.getNetworkStatus()||(d=null),e&&!e?.editor&&this.isEditor$?.value!==d&&!t?.sameUserPresentOnTab&&!t?.differentUserPresentOnTab&&this.isEditor$.next(d),pe(this.singleEditorLiveStateData,e))return;{t&&this.compareServerAndExternalData(u,t),i?.length>0&&i.forEach(C=>{C?.eventName&&this.analyticsService.trackEvent(C.eventName,C.properties)}),this.singleEditorLiveStateData=e,this.singleEditorLiveStateData$.next(e);let a;if(this.singleEditorLiveStateData&&typeof this.singleEditorLiveStateData=="object"&&(a=this.liveStateUtilsService.formatLiveStateSingleEditorModeData(JSON.parse(JSON.stringify(this.singleEditorLiveStateData)))),this.analyticsService.trackEvent(m.Events.LiveStateSync.SEM_SINGLE_EDITOR_LIVE_STATE_DATA_STATS,{singleEditorLiveStateData:a}),this.singleEditorLiveStateData?.editor){let C=this.authService.getUser();this.singleEditorLiveStateData?.editor?.userId!==C?.userId?this.makeReader():this.makeEditor()}else this.isEditor$?.value!==d&&this.isEditor$.next(d),this.enableInputElements(),this.enableElementEvents();this.editorAccessTimerInterval&&this.singleEditorLiveStateData?.requestEditorAccess?.status!=="pending"&&this.clearEditorAccessTimerInterval(),this.requestAccessTimer&&this.singleEditorLiveStateData?.requestEditorAccess?.status!=="pending"?this.clearRequestAccessTimer():this.singleEditorLiveStateData?.requestEditorAccess?.status==="pending"&&this.isUserEditor()?.isEditor&&this.isUserEditor()?.isEditorOnCurrentTab&&this.setRequestAccessTimer(this.singleEditorLiveStateData?.requestEditorAccess?.editorAccessTimeout||ee.LIVE_STATE_REQUEST_EDITOR_ACCESS_WAIT_TIME)}}catch{}})}compareServerAndExternalData(e,t){try{if(t){let i=this.authService.getUser(),s={isEditor:e?.editor?.userId===i?.userId,isEditorOnCurrentTab:e?.editor?.userId===i?.userId&&e?.tabId===this.tabId},l={isEditor:t?.sameUserPresentOnTab&&!t?.differentUserPresentOnTab,isEditorOnCurrentTab:!1};pe(s,l)||this.analyticsService.trackEvent(m.Events.LiveStateSync.SEM_SINGLE_EDITOR_DATA_MISMATCH_WITH_EXTERNAL,{serverUserEditorAccess:s,externalUserEditorAccess:l,serverData:e,externalData:t})}}catch(i){this.loggingService.catch("Error in LiveStateService compareServerAndExternalData: ",i)}}isFeatureAllowed(e){return this.configService.getConfig$().pipe(k(t=>!!t),D(t=>A(f({},e),{config:t})),y(t=>this.authService.getUser$().pipe(D(i=>A(f({},t),{user:i})))),y(t=>lt(t.config,t.user,ct.LIVE_STATE_SYNC)?p(A(f({},t),{featureAllowed:!0})):(this.loggingService.warn("Live state sync feature is not allowed."),p(A(f({},t),{featureAllowed:!1})))),ne((t,i)=>t?.featureAllowed===i?.featureAllowed))}getDataFromDocumentId(e){return this.databaseService.getDb().pipe(k(t=>!!t),y(t=>(this.db=t,this.configService?.getApiKey()&&this.documentPaths?.liveState?this.commonDbService.dbListener({feature:"liveStateSingleEditorMode",properties:{documentId:e??this.documentPaths?.documentId,organizationId:this.documentPaths?.organizationId,skipFirestore:!0}}).pipe(k(i=>!!i?.data),D(i=>i?.data&&typeof i?.data=="object"?JSON.parse(JSON.stringify(i?.data)):i?.data),Be(i=>(this.loggingService.catch("Error in LiveStateService getDataFromDocumentId: ",i),p({})))):p({}))),ne(Ee))}getLiveStateData$(e,t){try{return this.loggingService.log("%c[WB] Calling FUNCTION: getLiveStateData$","color: green;"),this.authService.getAuthState$().pipe(k(i=>!!i),y(i=>this.isFeatureAllowed({firebaseUser:i,liveStateData:{}})),y(i=>i.featureAllowed?this.iamService.isUserAllowed$().pipe(D(s=>(i.featureAllowed=s,i))):p(i)),y(i=>i.featureAllowed?this.authService.isPlanExpired$().pipe(D(s=>(i.featureAllowed=!s,i))):p(i)),y(i=>i.featureAllowed?p(i).pipe(y(s=>this.docService.getDocumentPaths$().pipe(D(l=>(this.documentPaths=l,s.documentPaths=l,s)))),y(s=>{let l=t?.listenToNewChangesOnly?1:0;return this.getLiveStateDataFromDatabase$(e).pipe(ne(Ee),ft(l))}),D(s=>{if(s)if(e){let l=Ie(e+""),u=s?.[l];if(u){let d=u?.data;if(u?.tabId&&this.tabId&&u?.tabId===this.tabId)return;if(u?.isDataStringified&&typeof d=="string")try{d=JSON.parse(d)}catch{}return d}else return}else{let l={};return Object.keys(s||{}).forEach(u=>{if(s[u]?.liveStateDataId){let d=s[u],a=d?.data;if(d?.isDataStringified&&typeof a=="string")try{a=JSON.parse(a)}catch{}l[d.liveStateDataId]=a}}),l}return s})):p(void 0).pipe(k(Boolean))),ne((i,s)=>JSON.stringify(i||{})===JSON.stringify(s||{})),k(i=>i!==void 0),D(i=>i))}catch(i){return this.loggingService.catch("Error in LiveStateService getLiveStateData$: ",i),p(null)}}getLiveStateDataFromDatabase$(e){try{return this.databaseService.getDb().pipe(k(t=>!!t),y(t=>{this.db=t;let i=e?Ie(e+""):void 0;return this.configService?.getApiKey()&&this.documentPaths?.liveState?this.commonDbService.dbListener({feature:i?"liveStateCustom":"allLiveStateCustoms",properties:{documentId:this.documentPaths?.documentId,organizationId:this.documentPaths?.organizationId,id:i,skipFirestore:!0}}).pipe(k(s=>!!s?.data),D(s=>s?.data),D(s=>{if(s)return i?{[i]:s}:s}),Be(s=>(this.loggingService.catch("Error in LiveStateService getLiveStateDataFromDatabase$: ",s),p(null)))):p(void 0)}))}catch(t){return this.loggingService.catch("Error in LiveStateService getLiveStateDataFromDatabase$: ",t),p(void 0)}}fetchLiveStateData(e){return Q(this,null,function*(){try{this.loggingService.log("%c[WB] Calling FUNCTION: fetchLiveStateData","color: green;");let t=this.databaseService.getDbValue(),i=this.authService.getUser(),s=this.docService.getDocumentPaths(),l=e?.liveStateDataId&&typeof e?.liveStateDataId=="string"?Ie(e.liveStateDataId):void 0,u=lt(this.configService.getConfig(),i,ct.LIVE_STATE_SYNC);if(this.authService.isPlanExpired()&&(u=!1),t&&i&&s?.liveState&&u){let a=yield this.commonDbService.getData({feature:l?"liveStateCustom":"allLiveStateCustoms",properties:{documentId:s?.documentId,organizationId:s?.organizationId,id:l,skipFirestore:!0}}).then(C=>C?l?{[l]:C}:C:null);if(a)if(l){let C=a?.[l];if(C){let P=C?.data;if(C?.isDataStringified&&typeof P=="string")try{P=JSON.parse(P)}catch{}return P}else return null}else{let C={};return Object.keys(a||{}).forEach(P=>{if(a[P]?.liveStateDataId){let O=a[P],w=O?.data;if(O?.isDataStringified&&typeof w=="string")try{w=JSON.parse(w)}catch{}C[O.liveStateDataId]=w}}),C}}return null}catch(t){return this.loggingService.catch("Error in LiveStateService fetchLiveStateData: ",t),null}})}setLiveStateData(e,t,i){return Q(this,null,function*(){this.loggingService.log("%c[WB] Calling FUNCTION: setLiveStateData","color: green;");try{let s=this.authService.getUser();if(e&&this.documentPaths?.liveState&&s){let l=Ie(e+""),u=!1;try{if(i?.merge&&typeof t=="object"){let a=yield this.commonDbService.getData({feature:"liveStateCustom",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",id:l,skipFirestore:!0}});if(a?.isDataStringified){let C=JSON.parse(a?.data);typeof t=="object"&&(t=f(f({},C),t))}}}catch{}try{typeof t=="object"&&(t=JSON.stringify(t),u=!0)}catch{}let d={id:l,lastUpdated:this.timestamp,liveStateDataId:e,data:t,updatedBy:s,tabId:this.tabId,isDataStringified:u};yield this.commonDbService.setData({feature:"liveStateCustom",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",id:l,skipFirestore:!0},data:JSON.parse(JSON.stringify(d))})}else this.loggingService.warn("liveStateDataId or documentPaths or user is null"),this.liveStateDataMapDraft?.custom||(this.liveStateDataMapDraft.custom={}),e&&(this.liveStateDataMapDraft.custom[e]=t)}catch(s){this.loggingService.catch("Error in LiveStateService _setLiveStateData: ",s)}})}getFormElements(){try{return this.loggingService.log("%c[WB] Calling FUNCTION: getInputElements","color: green;"),document.querySelectorAll("input, textarea, select, button, [contenteditable]")}catch(e){return this.loggingService.catch("Error in LiveStateService getInputElements: ",e),null}}disableInputElements(){try{this.loggingService.log("%c[WB] Calling FUNCTION: disableInputElements","color: green;"),this.getFormElements()?.forEach(t=>{if(this.isElementInsideSingleEditorModeContainerElements(t)&&!this.isSingleEditorModeDisabledForElement(t)&&!Rt(t)){let i=t?.hasAttribute("disabled");t?.hasAttribute("contenteditable")&&(i=t?.getAttribute("contenteditable")==="false"),i||(t.setAttribute("disabled","true"),t.setAttribute(ee.ATTRIBUTES.VELT_SYNC_ACCESS_AUTO,"true"),t?.hasAttribute("contenteditable")&&t.setAttribute("contenteditable","false"))}})}catch(e){this.loggingService.catch("Error in LiveStateService disableInputElements: ",e)}}enableInputElements(){try{this.loggingService.log("%c[WB] Calling FUNCTION: enableInputElements","color: green;"),this.getFormElements()?.forEach(t=>{t?.hasAttribute(ee.ATTRIBUTES.VELT_SYNC_ACCESS_AUTO)&&(t.removeAttribute("disabled"),t.removeAttribute(ee.ATTRIBUTES.VELT_SYNC_ACCESS_AUTO),t?.getAttribute("contenteditable")&&t.setAttribute("contenteditable","true"))})}catch(e){this.loggingService.catch("Error in LiveStateService enableInputElements: ",e)}}disableElementEvents(){try{this.loggingService.log("%c[WB] Calling FUNCTION: disableElementEvents","color: green;"),document.querySelectorAll(`[${ee.ATTRIBUTES.VELT_SYNC_ACCESS}]`)?.forEach(t=>{let i=this.domService.getXPath(t);i&&!this.preventEventsOnElementMap[i]&&(this.preventEventsOnElementMap[i]={element:t,events:{}},this.PREVENT_EVENTS.forEach(s=>{let l=Le(t,s,{capture:!0}).subscribe(u=>{try{u.preventDefault(),u.stopPropagation()}catch(d){this.loggingService.catch("Error in LiveStateService disableElementEvents subscription: ",d)}});this.preventEventsOnElementMap[i]?.events[s]?.unsubscribe(),this.preventEventsOnElementMap[i].events[s]=l}))})}catch(e){this.loggingService.catch("Error in LiveStateService disableElementClicks: ",e)}}enableElementEvents(){try{this.loggingService.log("%c[WB] Calling FUNCTION: enableElementEvents","color: green;"),Object.keys(this.preventEventsOnElementMap).forEach(e=>{let t=this.preventEventsOnElementMap[e];Object.keys(t.events||{}).forEach(i=>{t?.events[i]?.unsubscribe()})}),this.preventEventsOnElementMap={}}catch(e){this.loggingService.catch("Error in LiveStateService enableElementClicks: ",e)}}setUserAsEditor(e){return Q(this,null,function*(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: setUserAsEditor","color: green;"),this.user&&this.documentPaths?.liveStateSingleEditorMode){if(this.analyticsService.trackEvent(m.Events.LiveStateSync.SET_USER_AS_EDITOR_TRIGGERED,{editorUserId:this.user?.userSnippylyId,tabId:this.tabId}),!e?.skipEditorCheck){let i=yield this.fetchSingleEditorLiveStateDataFromDatabase();if(i?.editor?.userId&&i?.tabId){let s=yield ht(this.heartbeatService.getSpecificHeartbeat({userId:i?.editor?.userId,tabId:i?.tabId,documentId:this.documentPaths?.documentId})),l=null;s&&(l=this.singleEditorDecisionEngine.findOldestActiveSessionFromHeartbeats([s])),l||(i=null)}else i=null;if(i?.editor){let s=this.authService.getUser(),l=null;s?.userId===i?.editor?.userId?i?.tabId===this.tabId?l={code:"same_user_editor_current_tab",message:"Same user is already editor in current tab.",source:"setUserAsEditor"}:l={code:"same_user_editor_different_tab",message:"Same user is already editor in different tab.",source:"setUserAsEditor"}:l={code:"another_user_editor",message:"Another user is already editor.",source:"setUserAsEditor"};let u;return i&&typeof i=="object"&&(u=this.liveStateUtilsService.formatLiveStateSingleEditorModeData(JSON.parse(JSON.stringify(i)))),this.analyticsService.trackEvent(m.Events.LiveStateSync.SET_USER_AS_EDITOR_ERROR,{error:l,singleEditorLiveStateData:u}),{error:l}}}let t={editor:this.user,tabId:this.tabId,editorAt:this.timestamp};this.commonDbService.setData({feature:"liveStateSingleEditorMode",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0,rtdbTransaction:!0},data:JSON.parse(JSON.stringify(t))})}}catch(t){this.loggingService.catch("Error in LiveStateService setUserAsEditor: ",t)}})}fetchSingleEditorLiveStateDataFromDatabase(){return Q(this,null,function*(){try{return this.loggingService.log("%c[WB] Calling FUNCTION: fetchSingleEditorLiveStateDataFromDatabase","color: green;"),yield this.commonDbService.getData({feature:"liveStateSingleEditorMode",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0}})}catch(e){return this.loggingService.catch("Error in LiveStateService fetchSingleEditorLiveStateDataFromDatabase: ",e),null}})}setRequestAccessTimer(e){try{this.loggingService.log("%c[WB] Calling FUNCTION: setRequestAccessTimer","color: green;"),this.requestAccessTimer||(this.requestAccessTimer=setTimeout(()=>{this.getEditorAccessTransferOnTimeOut()&&this.acceptEditorAccessRequest(),this.clearRequestAccessTimer()},e*1e3),this.setEditorAccessTimerInterval(e))}catch(t){this.loggingService.catch("Error in LiveStateService setRequestAccessTimer: ",t)}}clearRequestAccessTimer(){try{this.loggingService.log("%c[WB] Calling FUNCTION: clearRequestAccessTimer","color: green;"),this.requestAccessTimer&&(clearTimeout(this.requestAccessTimer),this.requestAccessTimer=null)}catch(e){this.loggingService.catch("Error in LiveStateService clearRequestAccessTimer: ",e)}}requestEditorAccess(){this.loggingService.log("%c[WB] Calling FUNCTION: requestEditorAccess","color: green;");try{return this.serverConnectionState$.value===K.OFFLINE?(this.loggingService.catch("User is offline."),p(null)):(this.analyticsService.trackEvent(m.Events.LiveStateSync.REQUEST_EDITOR_ACCESS_TRIGGERED),new mt(e=>{let t=null;try{if(this.user&&this.documentPaths?.liveStateSingleEditorMode){let i=this.getEditorAccessTimeout(),s=this.realtimeAdapter.rtdbRef(this.db,`${this.documentPaths?.liveStateSingleEditorMode}`),l={requestEditorAccess:{user:this.user,requestedAt:this.timestamp,status:"pending",editorAccessTimeout:i,tabId:this.tabId}};this.commonDbService.updateData({feature:"liveStateSingleEditorMode",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0,rtdbTransaction:!0},errorCallback:u=>{this.loggingService.catch("Error in LiveStateService requestEditorAccess: ",u),e.next(null),e.complete()},callback:()=>{i&&(this.requestAccessTimer=setTimeout(()=>{this.getEditorAccessTransferOnTimeOut()&&this.setUserAsEditor({skipEditorCheck:!0})},(i+3)*1e3),this.setEditorAccessTimerInterval(i+3)),t=this.getSingleEditorLiveStateData$().subscribe(u=>{u&&(u?.requestEditorAccess?u?.requestEditorAccess?.status==="cancelled"&&(e.next(null),e.complete()):u?.editor?.userId===this.user?.userId?(e.next(!0),e.complete()):(e.next(!1),e.complete()))})},data:JSON.parse(JSON.stringify(l))})}else e.next(!1),e.complete()}catch(i){this.loggingService.catch("Error in LiveStateService requestEditorAccess: ",i),e.next(null),e.complete()}return()=>{t&&t?.unsubscribe()}}))}catch(e){return this.loggingService.catch("Error in LiveStateService requestEditorAccess: ",e),p(null)}}makeEditor(){try{this.loggingService.log("%c[WB] Calling FUNCTION: makeEditor","color: green;");let e=this.singleEditorLiveStateData?.tabId===this.tabId;this.analyticsService.trackEvent(m.Events.LiveStateSync.SEM_MAKE_EDITOR_TRIGGERED,{editorUserId:this.singleEditorLiveStateData?.editor?.userId,tabId:this.tabId,editorTabId:this.singleEditorLiveStateData?.tabId,isEditor:!0,isEditorOnCurrentTab:e}),this.isEditor$.next({isEditor:!0,isEditorOnCurrentTab:e}),this.getSingleEditorModeConfig()?.customMode||(!this.getSingleEditorModeConfig()?.singleTabEditor||e?(this.enableInputElements(),this.enableElementEvents()):(this.disableInputElements(),this.disableElementEvents())),this.fetchSingleEditorLiveStateDataFromDatabase().then(t=>{this.analyticsService.trackEvent(m.Events.LiveStateSync.SEM_SINGLE_EDITOR_LIVE_STATE_DATA_ON_MAKE_EDITOR,{editorUserId:this.singleEditorLiveStateData?.editor?.userId,tabId:this.tabId,editorTabId:this.singleEditorLiveStateData?.tabId,isEditor:!0,isEditorOnCurrentTab:e,singleEditorLiveStateDataOnServer:t})}).catch(t=>{})}catch(e){this.loggingService.catch("Error in LiveStateService makeEditor: ",e)}}makeReader(){try{this.loggingService.log("%c[WB] Calling FUNCTION: makeReader","color: green;"),this.analyticsService.trackEvent(m.Events.LiveStateSync.SEM_MAKE_READER_TRIGGERED,{editorUserId:this.singleEditorLiveStateData?.editor?.userId,tabId:this.tabId,editorTabId:this.singleEditorLiveStateData?.tabId,isEditor:!1,isEditorOnCurrentTab:!1}),this.isEditor$.next({isEditor:!1,isEditorOnCurrentTab:!1}),this.getSingleEditorModeConfig()?.customMode||(this.disableInputElements(),this.disableElementEvents()),this.fetchSingleEditorLiveStateDataFromDatabase().then(e=>{this.analyticsService.trackEvent(m.Events.LiveStateSync.SEM_SINGLE_EDITOR_LIVE_STATE_DATA_ON_MAKE_READER,{editorUserId:this.singleEditorLiveStateData?.editor?.userId,tabId:this.tabId,editorTabId:this.singleEditorLiveStateData?.tabId,isEditor:!1,isEditorOnCurrentTab:!1,singleEditorLiveStateDataOnServer:e})}).catch(e=>{})}catch(e){this.loggingService.catch("Error in makeReader: ",e)}}acceptEditorAccessRequest(){return Q(this,null,function*(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: acceptEditorAccessRequest","color: green;"),this.serverConnectionState$.value===K.OFFLINE){this.loggingService.catch("User is offline.");return}if(this.user&&this.singleEditorLiveStateData?.requestEditorAccess&&this.isUserEditor()?.isEditor&&this.documentPaths?.liveStateSingleEditorMode){let e=this.singleEditorLiveStateData?.requestEditorAccess?.user,t=this.singleEditorLiveStateData?.requestEditorAccess?.tabId;if(e&&t){let i={editor:e,requestEditorAccess:null,tabId:t,editorAt:this.timestamp};this.commonDbService.updateData({feature:"liveStateSingleEditorMode",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0,rtdbTransaction:!0},data:JSON.parse(JSON.stringify(i))}),this.analyticsService.trackEvent(m.Events.LiveStateSync.ACCEPT_EDITOR_ACCESS_REQUEST_TRIGGERED,{editorUserId:e?.userSnippylyId,tabId:t})}}}catch(e){this.loggingService.catch("Error in acceptEditorAccessRequest: ",e)}})}rejectEditorAccessRequest(){return Q(this,null,function*(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: rejectEditorAccessRequest","color: green;"),this.serverConnectionState$.value===K.OFFLINE){this.loggingService.catch("User is offline.");return}if(this.user&&this.singleEditorLiveStateData?.requestEditorAccess&&this.isUserEditor()?.isEditor&&this.documentPaths?.liveStateSingleEditorMode){let e={requestEditorAccess:null};this.commonDbService.updateData({feature:"liveStateSingleEditorMode",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0,rtdbTransaction:!0},data:JSON.parse(JSON.stringify(e))}),this.analyticsService.trackEvent(m.Events.LiveStateSync.REJECT_EDITOR_ACCESS_REQUEST_TRIGGERED)}}catch(e){this.loggingService.catch("Error in LiveStateService rejectEditorAccessRequest: ",e)}})}cancelEditorAccessRequest(){return Q(this,null,function*(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: cancelEditorAccessRequest","color: green;"),this.serverConnectionState$.value===K.OFFLINE){this.loggingService.catch("User is offline.");return}if(this.user&&this.singleEditorLiveStateData?.requestEditorAccess&&this.documentPaths?.liveStateSingleEditorMode){let e={requestEditorAccess:A(f({},this.singleEditorLiveStateData?.requestEditorAccess),{status:"cancelled"})};this.commonDbService.updateData({feature:"liveStateSingleEditorMode",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0,rtdbTransaction:!0},data:JSON.parse(JSON.stringify(e))}),e={requestEditorAccess:null},this.commonDbService.updateData({feature:"liveStateSingleEditorMode",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0,rtdbTransaction:!0},data:JSON.parse(JSON.stringify(e))}),this.analyticsService.trackEvent(m.Events.LiveStateSync.CANCEL_EDITOR_ACCESS_REQUEST_TRIGGERED)}}catch(e){this.loggingService.catch("Error in LiveStateService cancelEditorAccessRequest: ",e)}})}editCurrentTab(){return Q(this,null,function*(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: editCurrentTab","color: green;"),this.serverConnectionState$.value===K.OFFLINE){this.loggingService.catch("User is offline.");return}if(this.user&&this.isUserEditor()?.isEditor&&!this.isUserEditor()?.isEditorOnCurrentTab&&this.documentPaths?.liveStateSingleEditorMode){let e={tabId:this.tabId,editor:this.user,editorAt:this.timestamp};this.commonDbService.updateData({feature:"liveStateSingleEditorMode",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0,rtdbTransaction:!0},data:JSON.parse(JSON.stringify(e))}),this.analyticsService.trackEvent(m.Events.LiveStateSync.EDIT_CURRENT_TAB_TRIGGERED,{tabId:this.tabId})}}catch(e){this.loggingService.catch("Error in LiveStateService editCurrentTab: ",e)}})}isUserEditor$(){try{return this.loggingService.log("%c[WB] Calling FUNCTION: isUserEditor$","color: green;"),this.isEditor$.asObservable().pipe(ne(Ee))}catch(e){return this.loggingService.catch("Error in LiveStateService isUserEditor$: ",e),p(null)}}isUserEditor(){try{return this.loggingService.log("%c[WB] Calling FUNCTION: isUserEditor","color: green;"),this.isEditor$.value}catch(e){return this.loggingService.catch("Error in LiveStateService isUserEditor: ",e),null}}getEditor$(){try{return this.loggingService.log("%c[WB] Calling FUNCTION: getEditor$","color: green;"),this.getSingleEditorLiveStateData$().pipe(D(e=>e?.editor||null),ne())}catch(e){return this.loggingService.catch("Error in LiveStateService getEditor$: ",e),p(null)}}isEditorAccessRequested$(){try{return this.loggingService.log("%c[WB] Calling FUNCTION: isEditorAccessRequested$","color: green;"),this.isUserEditor$().pipe(y(e=>e?.isEditor?this.singleEditorLiveStateData$.pipe(D(t=>t?.requestEditorAccess?{requestStatus:"requested",requestedBy:t?.requestEditorAccess?.user}:null)):p(null)),ne((e,t)=>JSON.stringify(e||{})===JSON.stringify(t||{})))}catch(e){return this.loggingService.catch("Error in LiveStateService isEditorAccessRequested$: ",e),p(null)}}removeEditorAccess(e){return Q(this,null,function*(){try{this.loggingService.log("%c[WB] Calling FUNCTION: removeEditorAccess","color: green;"),this.analyticsService.trackEvent(m.Events.LiveStateSync.REMOVE_EDITOR_ACCESS,{removeEditorAccessMetadata:e?.metadata});let t=e?.documentPaths??this.documentPaths;(this.user||this.authService.getAuthUser())&&t?.liveStateSingleEditorMode&&(yield this.commonDbService.deleteData({feature:"liveStateSingleEditorMode",properties:{documentId:t?.documentId??"",organizationId:t?.organizationId??"",skipFirestore:!0}}))}catch(t){this.loggingService.catch("Error in LiveStateService removeEditorAccess: ",t)}})}getSingleEditorLiveStateData$(){return this.singleEditorLiveStateData$.asObservable().pipe(ne(Ee))}subscribeAutoSyncState(){return this.loggingService.log("%c[WB] Calling FUNCTION: getOnlineUsersOnCurrentDocument","color: green;"),this.authService.getAuthState$().pipe(k(e=>!!e),y(e=>this.isFeatureAllowed({firebaseUser:e,liveStateData:{}})),y(e=>e.featureAllowed?this.iamService.isUserAllowed$().pipe(D(t=>(e.featureAllowed=t,e))):p(e)),y(e=>e.featureAllowed?this.authService.isPlanExpired$().pipe(D(t=>(e.featureAllowed=!t,e))):p(e)),y(e=>e.featureAllowed?p(e).pipe(y(t=>this.docService.getDocumentPaths$().pipe(k(i=>!!i),D(i=>(this.documentPaths=i,t.documentPaths=i,t)))),y(t=>this.domService.onNetworkStatusChange$().pipe(k(i=>i),D(()=>t))),y(t=>this.getLiveStateAutoSyncStateDataFromDocumentId().pipe(D(i=>(t.liveStateData=i,f({},t))))),D(t=>{if(t.liveStateData)this.liveStateAutoSyncStateData$.next(t.liveStateData);else{let i=this.liveStateAutoSyncStateData$.value;i&&Object.keys(i).length>0&&this.liveStateAutoSyncStateData$.next({})}return t})):p({})))}getLiveStateAutoSyncStateDataFromDocumentId(e){return this.databaseService.getDb().pipe(k(t=>!!t),y(t=>(this.db=t,this.configService?.getApiKey()&&this.documentPaths?.liveState?this.commonDbService.dbListener({feature:"liveStateAutoSyncState",properties:{documentId:e??this.documentPaths?.documentId,organizationId:this.documentPaths?.organizationId,skipFirestore:!0}}).pipe(k(i=>!!i?.data),D(i=>i?.data&&typeof i?.data=="object"?JSON.parse(JSON.stringify(i?.data)):i?.data),Be(i=>(this.loggingService.catch("Error in LiveStateService getLiveStateAutoSyncStateDataFromDocumentId: ",i),p({})))):p({}))),ne(Ee))}enableSingleEditorMode(e){try{if(this.singleEditorMode$.value===!0)return;this.singleEditorMode$.next(!0),e?this.singleEditorModeConfig$.next(e):this.singleEditorModeConfig$.next(new Ut)}catch(t){this.loggingService.catch("Error in LiveStateService enableSingleEditorMode: ",t)}}disableSingleEditorMode(){try{if(this.singleEditorMode$.value===!1)return;this.singleEditorMode$.next(!1)}catch(e){this.loggingService.catch("Error in LiveStateService disableSingleEditorMode: ",e)}}getSingleEditorMode$(){return this.singleEditorMode$.asObservable()}getSingleEditorMode(){return this.singleEditorMode$.value}getSingleEditorModeConfig$(){return this.singleEditorModeConfig$.asObservable()}getSingleEditorModeConfig(){return this.singleEditorModeConfig$.value}enableAutoSyncState(){try{if(this.autoSyncState$.value===!0)return;this.autoSyncState$.next(!0)}catch(e){this.loggingService.catch("Error in LiveStateService enableAutoSyncState: ",e)}}disableAutoSyncState(){try{if(this.autoSyncState$.value===!1)return;this.autoSyncState$.next(!1)}catch(e){this.loggingService.catch("Error in LiveStateService disableAutoSyncState: ",e)}}getAutoSyncState$(){return this.autoSyncState$.asObservable()}getAutoSyncState(){return this.autoSyncState$.value}setEditorAccessTimeout(e){try{this.loggingService.log("%c[WB] Calling FUNCTION: setEditorAccessTimeout","color: green;"),e&&this.editorAccessTimeout$.next(e)}catch(t){this.loggingService.catch("Error in LiveStateService setEditorAccessTimeout: ",t)}}getEditorAccessTimeout$(){return this.editorAccessTimeout$.asObservable()}getEditorAccessTimeout(){return this.editorAccessTimeout$.value}enableEditorAccessTransferOnTimeOut(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: enableEditorAccessTransferOnTimeOut","color: green;"),this.editorAccessTransferOnTimeOut$.value===!0)return;this.editorAccessTransferOnTimeOut$.next(!0)}catch(e){this.loggingService.catch("Error in LiveStateService enableEditorAccessTransferOnTimeOut: ",e)}}disableEditorAccessTransferOnTimeOut(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: disableEditorAccessTransferOnTimeOut","color: green;"),this.editorAccessTransferOnTimeOut$.value===!1)return;this.editorAccessTransferOnTimeOut$.next(!1)}catch(e){this.loggingService.catch("Error in LiveStateService disableEditorAccessTransferOnTimeOut: ",e)}}getEditorAccessTransferOnTimeOut$(){return this.editorAccessTransferOnTimeOut$.asObservable()}getEditorAccessTransferOnTimeOut(){return this.editorAccessTransferOnTimeOut$.value}enableDefaultSingleEditorUI(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: enableDefaultSingleEditorUI","color: green;"),this.defaultSingleEditorUIEnabled$.value===!0)return;this.defaultSingleEditorUIEnabled$.next(!0)}catch(e){this.loggingService.catch("Error in LiveStateService enableDefaultSingleEditorUI: ",e)}}disableDefaultSingleEditorUI(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: disableDefaultSingleEditorUI","color: green;"),this.defaultSingleEditorUIEnabled$.value===!1)return;this.defaultSingleEditorUIEnabled$.next(!1)}catch(e){this.loggingService.catch("Error in LiveStateService disableDefaultSingleEditorUI: ",e)}}getDefaultSingleEditorUIEnabled$(){return this.defaultSingleEditorUIEnabled$.asObservable()}getDefaultSingleEditorUIEnabled(){return this.defaultSingleEditorUIEnabled$.value}setEditorAccessTimerInterval(e){try{this.loggingService.log("%c[WB] Calling FUNCTION: setEditorAccessTimerInterval","color: green;"),this.clearEditorAccessTimerInterval(),e>0&&(this.editorAccessTimer$.next({state:"inProgress",durationLeft:e}),this.editorAccessTimerInterval=setInterval(()=>{try{e-=1,e<0?this.clearEditorAccessTimerInterval():e?this.editorAccessTimer$.next({state:"inProgress",durationLeft:e}):this.editorAccessTimer$.next({state:"completed"})}catch(t){this.loggingService.catch("Error in LiveStateService setEditorAccessTimerCountdown interval: ",t),this.clearEditorAccessTimerInterval()}},1e3))}catch(t){this.loggingService.catch("Error in LiveStateService setEditorAccessTimerCountdown: ",t),this.clearEditorAccessTimerInterval()}}clearEditorAccessTimerInterval(){try{this.loggingService.log("%c[WB] Calling FUNCTION: clearEditorAccessTimerInterval","color: green;"),this.editorAccessTimerInterval&&(clearInterval(this.editorAccessTimerInterval),this.editorAccessTimerInterval=null,this.editorAccessTimer$.next({state:"idle"}))}catch(e){this.loggingService.catch("Error in LiveStateService clearEditorAccessTimerInterval: ",e)}}getEditorAccessTimer$(){return this.editorAccessTimer$.asObservable()}onServerConnectionStateChange$(){return this.serverConnectionState$.asObservable()}updateExternalUserPresence(e){try{this.loggingService.log("%c[WB] Calling FUNCTION: updateExternalUserPresence","color: green;"),this.externalUserPresence$.next(e)}catch(t){this.loggingService.catch("Error in LiveStateService updateExternalUserPresence: ",t)}}getExternalUserPresence$(){return this.externalUserPresence$.asObservable().pipe(ne(Ee))}getExternalUserPresence(){return this.externalUserPresence$.value}enableHeartbeat(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: enableHeartbeat","color: green;"),this.heartbeat$.value===!0)return;this.heartbeat$.next(!0)}catch(e){this.loggingService.catch("Error in LiveStateService enableHeartbeat: ",e)}}disableHeartbeat(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: disableHeartbeat","color: green;"),this.heartbeat$.value===!1)return;this.heartbeat$.next(!1)}catch(e){this.loggingService.catch("Error in LiveStateService disableHeartbeat: ",e)}}detectLiveSyncInputs(){try{document.querySelectorAll(`[${ee.ATTRIBUTES.VELT_SYNC_STATE}]`)?.forEach(t=>{this.subscribeInputChanges(t)})}catch(e){this.loggingService.catch("Error in LiveStateService detectLiveSyncInputs: ",e)}}subscribeInputChanges(e){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: subscribeInputChanges","color: green;"),e){let t=e.tagName,i=this.domService.getXPath(e),s=Ie(i);if(this.inputChangeSubscriptionMap[s])this.loggingService.warn("subscription already exists",s,e);else{this.inputChangeSubscriptionMap[s]={id:s,element:e};let l;switch(t?.toLowerCase()){case"input":l=Le(e,"input").pipe(je(300)).subscribe(d=>{let a={value:d?.target?.value,tagName:d?.target?.tagName,type:d?.target?.type};this.setLiveStateSyncInputData(d?.target,a)});break;case"textarea":l=Le(e,"input").pipe(je(300)).subscribe(d=>{let a={value:d?.target?.value,tagName:d?.target?.tagName};this.setLiveStateSyncInputData(d?.target,a)});break;default:e.getAttribute("contenteditable")&&(l=Le(e,"input").pipe(je(300)).subscribe(d=>{let a={innerText:d?.target?.innerText,innerHTML:this.domService.sanitizeHtml(d?.target?.innerHTML),tagName:d?.target?.tagName,isContentEditable:!0};this.setLiveStateSyncInputData(d?.target,a)}));break}l&&(this.inputChangeSubscriptionMap[s]?.subscriptions||(this.inputChangeSubscriptionMap[s]={subscriptions:[]}),this.inputChangeSubscriptionMap[s].subscriptions?.push(l))}}}catch(t){this.loggingService.catch("Error in LiveStateService subscribeInputChanges: ",t)}}unsubscribeInputChanges(){try{this.loggingService.log("%c[WB] Calling FUNCTION: unsubscribeInputChanges","color: green;"),Object.keys(this.inputChangeSubscriptionMap).forEach(e=>{this.inputChangeSubscriptionMap[e]?.subscriptions?.forEach(i=>{i.unsubscribe()})}),this.inputChangeSubscriptionMap={}}catch(e){this.loggingService.catch("Error in LiveStateService unsubscribeInputChanges: ",e)}}setLiveStateSyncInputData(e,t){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: setLiveStateSyncInputData","color: green;"),this.user&&this.documentPaths?.liveState){let i=this.domService.getXPath(e),s=Ie(i),l={id:s,lastUpdated:this.timestamp,liveStateDataId:i,data:t,updatedBy:this.user,tabId:this.tabId};this.commonDbService.updateData({feature:"liveStateAutoSyncStateCurrent",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0},data:JSON.parse(JSON.stringify(l))}),this.commonDbService.updateData({feature:"liveStateAutoSyncStateHistoryId",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",id:s,skipFirestore:!0},data:JSON.parse(JSON.stringify(l))})}}catch(i){this.loggingService.catch("Error in LiveStateService setLiveStateSyncInputData: ",i)}}updateLiveStateSyncInputDataLocally(e){try{this.loggingService.log("%c[WB] Calling FUNCTION: updateLiveStateSyncInputDataLocally","color: green;"),this.user&&Object.keys(e).forEach(t=>{let i=e[t],s=this.domService.getElementFromXPath(i?.liveStateDataId),l=!1;if(i?.updatedBy?.userSnippylyId!==this.user?.userSnippylyId)l=!0;else{let u=i?.tabId&&this.tabId&&i?.tabId!==this.tabId,d=s?.contains(document.activeElement);u&&!Pt()&&!d&&(l=!0)}if(l&&s)switch(s.value=i?.data?.value,s.tagName?.toLowerCase()){case"input":s.value=i?.data?.value;break;case"textarea":s.value=i?.data?.value;break;default:s.getAttribute("contenteditable")&&(s.innerHTML=this.domService.sanitizeHtml(i?.data?.innerHTML))}})}catch(t){this.loggingService.catch("Error in LiveStateService updateLiveStateSyncInputDataLocally: ",t)}}setSingleEditorModeContainerIds(e){this.singleEditorModeContainerIds$.next(e||[])}getSingleEditorModeContainerIds(){return this.singleEditorModeContainerIds$.asObservable()}isElementInsideSingleEditorModeContainerElements(e){try{this.loggingService.log("%c[WB] Calling FUNCTION: isElementInsideSingleEditorModeContainerElements","color: green;");let t=this.singleEditorModeContainerIds$.value,i=document.querySelectorAll(`[${ee.ATTRIBUTES.VELT_SINGLE_EDITOR_MODE_CONTAINER}]`);if(!t?.length&&!i?.length)return!0;if(t?.length)for(let s=0;s<t.length;s++){let l=document.getElementById(t[s]);if(l&&l.contains(e))return!0}if(i?.length)for(let s=0;s<i.length;s++){let l=i[s];if(l&&l.contains(e))return!0}return!1}catch(t){return this.loggingService.catch("Error in LiveStateService isElementInsideSingleEditorModeContainerElements: ",t),!1}}isSingleEditorModeDisabledForElement(e){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: isSingleEditorModeDisabledForElement","color: green;"),e){if(e.getAttribute(ee.ATTRIBUTES.VELT_SYNC_ACCESS_DISABLED))return!0;{let i=e?.parentElement;if(i)return this.isSingleEditorModeDisabledForElement(i)}}return!1}catch(t){return this.loggingService.catch("Error in LiveStateService isSingleEditorModeDisabledForElement: ",t),!1}}updateOnDatabaseDisconnect(){return this.loggingService.log("%c[WB] Calling FUNCTION: updateOnDatabaseDisconnect","color: green;"),this.isUserEditor$().pipe(Ge(e=>{try{if(this.documentPaths?.liveStateSingleEditorMode){let t=this.realtimeAdapter.rtdbRef(this.db,`${this.documentPaths?.liveStateSingleEditorMode}`);e?.isEditor&&(!this.getSingleEditorModeConfig()?.singleTabEditor||e?.isEditorOnCurrentTab)?this.realtimeAdapter.rtdbOnDisconnectRemove("liveState",t):this.realtimeAdapter.rtdbOnDisconnectCancel("liveState",t)}}catch(t){this.loggingService.catch("Error in LiveStateService updateOnDatabaseDisconnect tap: ",t)}}))}updateServerStateOnDatabaseDisconnect(){return this.loggingService.log("%c[WB] Calling FUNCTION: updateServerStateOnDatabaseDisconnect","color: green;"),this.authService.getAuthState$().pipe(k(e=>!!e),y(e=>this.docService.getDocumentPaths$().pipe(D(t=>e))),Ge(e=>Q(this,null,function*(){try{if(this.connectionListenerUnsubscribe&&(this.connectionListenerUnsubscribe(),this.connectionListenerUnsubscribe=null),this.offlineTimer&&(clearTimeout(this.offlineTimer),this.offlineTimer=null),this.docService.getDocumentPaths()?.liveState&&e){let i=this.realtimeAdapter.rtdbRef(this.db,".info/connected"),s=!0,l=1500;this.connectionListenerUnsubscribe=this.realtimeAdapter.rtdbOnValue("liveState",i,u=>{let d=u.val();if(s&&d===!1){s=!1;return}s=!1,this.offlineTimer&&(clearTimeout(this.offlineTimer),this.offlineTimer=null),d?this.serverConnectionState$.value===K.OFFLINE&&this.serverConnectionState$.next(K.ONLINE):this.offlineTimer=setTimeout(()=>{this.serverConnectionState$.next(K.OFFLINE),this.offlineTimer=null},l)})}}catch(t){this.loggingService.catch("Error in updateServerStateOnDatabaseDisconnect:",t)}})))}signOutUser(e){return new Promise((t,i)=>{try{this.documentPaths?.liveStateSingleEditorMode&&e?this.commonDbService.getData({feature:"liveStateSingleEditorMode",properties:{documentId:this.documentPaths?.documentId,organizationId:this.documentPaths?.organizationId,skipFirestore:!0}}).then(s=>{s&&this.isUserEditor()?.isEditor&&(!this.getSingleEditorModeConfig()?.singleTabEditor||this.isUserEditor()?.isEditorOnCurrentTab)&&this.removeEditorAccess({metadata:{from:"signOutUser-liveStateService",reason:"User signed out"}}),t(null)}).catch(s=>{this.loggingService.catch("Error in signOutUser subscription: ",s),i(s)}):t(null)}catch(s){this.loggingService.catch("Error in signOutUser:",s),i(s)}})}getSemStats(){try{let e=!!this.authService?.getUser(),t=!!this.docService?.getDocumentPaths(),i=this.singleEditorMode$.value,s=!!this.singleEditorModeConfig$.value,l=this.isUserEditor(),u;this.singleEditorLiveStateData$.value&&typeof this.singleEditorLiveStateData$.value=="object"&&(u=this.liveStateUtilsService?.formatLiveStateSingleEditorModeData(JSON.parse(JSON.stringify(this.singleEditorLiveStateData$.value))));let d=this.getExternalUserPresence();return{userAvailable:e,documentPathsAvailable:t,singleEditorModeEnabled:i,singleEditorModeConfig:s,isEditor:l,singleEditorLiveStateData:u,userPresence:d}}catch(e){this.loggingService.catch("Error in LiveStateService getSemStats: ",e)}}get timestamp(){return this.commonDbService.getServerTimestamp()}};r.\u0275fac=function(t){return new(t||r)(L(Lt),L(Xe),L(Oe),L(Ft),L(Ze),L(qt),L($t),L(De),L(Qt),L(zt),L(c),L(Gt),L(nt),L(Bt),L(et),L(Zt),L(Ye),L(jt))},r.\u0275prov=Ae({token:r,factory:r.\u0275fac,providedIn:"root"});let n=r;return n})();var H=class{constructor(){this.singleEditorMode=!1,this.defaultSingleEditorUIEnabled=!1,this.editAccessRequested=!1,this.leaderName="",this.type="reader",this.requestEditorAccessCountdown=0,this.shadowDom=!0,this.requestEditorAccess=()=>{},this.cancelEditorAccessRequest=()=>{},this.rejectEditorAccessRequest=()=>{},this.acceptEditorAccessRequest=()=>{},this.editCurrentTab=()=>{}}};var ti=n=>({componentConfigSignal:n}),fi=(n,r)=>({condition:n,data:r}),Ci=(n,r,o,e,t)=>({template:n,context:r,componentName:"velt-single-editor-mode-panel-countdown-wireframe",variant:o,setIfCondition:e,componentElementRef:t});function bi(n,r){if(n&1&&(b(0),X(1),_()),n&2){let o=g(3).ngIf;h(),Z(" ",o.requestEditorAccessCountdown," ")}}function _i(n,r){if(n&1&&(R(0,"span",3),S(1,bi,2,1,"ng-container",4),N()),n&2){let o=g(2).ngIf,e=g();h(),v("veltDynamicTemplate",G(3,Ci,e.template,x(1,ti,e.componentConfigSignal),o==null?null:o.variant,e.setIfCondition.bind(e),e.elementRef))}}function Ii(n,r){if(n&1&&(b(0),S(1,_i,2,9,"span",2),_()),n&2){let o=g().ngIf;h(),v("ngIf",o.type==="editor"&&o.requestEditorAccessCountdown)}}function yi(n,r){if(n&1&&(b(0),S(1,Ii,2,1,"ng-container",1),_()),n&2){let o=g();h(),v("veltIf",j(3,fi,o.conditionSignal(),x(1,ti,o.componentConfigSignal)))}}var xe=(()=>{let r=class r extends te{constructor(e,t,i){super(e,t,i),this.elementRef=e,this.dynamicDataService=t,this.loggingService=i,this.componentId="velt-single-editor-mode-panel-countdown";try{super.initializeComponentConfigSignal(new H)}catch(s){this.loggingService.catch("Error in SingleEditorModePanelCountdownComponent constructor:",s)}}ngOnInit(){try{super.ngOnInit(),this.setupA11yAttributes()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelCountdownComponent ngOnInit: ",e)}}ngOnDestroy(){try{super.ngOnDestroy()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelCountdownComponent ngOnDestroy: ",e)}}setupA11yAttributes(){try{this.elementRef.nativeElement.setAttribute("data-testid",this.componentId+"-container")}catch(e){this.loggingService.catch("Error in SingleEditorModePanelCountdownComponent setupA11yAttributes:",e)}}};r.\u0275fac=function(t){return new(t||r)(E(F),E(U),E(c))},r.\u0275cmp=q({type:r,selectors:[["velt-single-editor-mode-panel-countdown"]],standalone:!1,features:[$],decls:1,vars:1,consts:[[4,"ngIf"],[4,"veltIf"],["class","velt-single-editor-mode-panel-countdown-text countdown-text","data-velt-ignore","",4,"ngIf"],["data-velt-ignore","",1,"velt-single-editor-mode-panel-countdown-text","countdown-text"],[4,"veltDynamicTemplate"]],template:function(t,i){t&1&&S(0,yi,2,6,"ng-container",0),t&2&&v("ngIf",i.componentConfigSignal())},dependencies:[B,V,W],styles:["html[_ngcontent-%COMP%]{--velt-base-rem-unit: 1}*[data-snippyly-element=true][_ngcontent-%COMP%], *[data-velt-element=true][_ngcontent-%COMP%]{font-family:var(--velt-default-font-family)}velt-wireframe[_ngcontent-%COMP%]{display:none!important}body.velt-pin-dragging[_ngcontent-%COMP%] iframe[_ngcontent-%COMP%]{pointer-events:none!important}[_nghost-%COMP%]:empty{display:none}.velt-single-editor-mode-panel-countdown-text[_ngcontent-%COMP%]{background:var(--velt-accent);color:var(--velt-white);display:flex;justify-content:center;align-items:center;padding:var(--velt-spacing-xs);border-radius:var(--velt-border-radius-full);width:calc((1rem + 0px) * var(--velt-base-rem-unit));height:calc((1rem + 0px) * var(--velt-base-rem-unit));font-style:normal;font-weight:600;font-size:var(--velt-font-size-2xs)}"],changeDetection:0});let n=r;return n})();var ii=n=>({componentConfigSignal:n}),Ai=(n,r)=>({condition:n,data:r}),Di=(n,r,o,e,t)=>({template:n,context:r,componentName:"velt-single-editor-mode-panel-edit-here-wireframe",variant:o,setIfCondition:e,componentElementRef:t});function Oi(n,r){n&1&&(b(0),X(1),J(2,"translate"),_()),n&2&&(h(),Z(" ",z(2,1,"Edit here")," "))}function Mi(n,r){if(n&1){let o=ge();R(0,"button",3),ue("click",function(){le(o);let t=g(2).ngIf;return de(t.editCurrentTab())}),S(1,Oi,3,3,"ng-container",4),N()}if(n&2){let o=g(2).ngIf,e=g();h(),v("veltDynamicTemplate",G(3,Di,e.template,x(1,ii,e.componentConfigSignal),o==null?null:o.variant,e.setIfCondition.bind(e),e.elementRef))}}function Li(n,r){if(n&1&&(b(0),S(1,Mi,2,9,"button",2),_()),n&2){let o=g().ngIf;h(),v("ngIf",o.type==="editor"&&(o.singleEditorConfig==null?null:o.singleEditorConfig.singleTabEditor)&&!(o.isUserEditor!=null&&o.isUserEditor.isEditorOnCurrentTab)&&!o.requestEditorAccessCountdown)}}function xi(n,r){if(n&1&&(b(0),S(1,Li,2,1,"ng-container",1),_()),n&2){let o=g();h(),v("veltIf",j(3,Ai,o.conditionSignal(),x(1,ii,o.componentConfigSignal)))}}var Ue=(()=>{let r=class r extends te{constructor(e,t,i){super(e,t,i),this.elementRef=e,this.dynamicDataService=t,this.loggingService=i,this.componentId="velt-single-editor-mode-panel-edit-here";try{super.initializeComponentConfigSignal(new H)}catch(s){this.loggingService.catch("Error in SingleEditorModePanelEditHereComponent constructor:",s)}}ngOnInit(){try{super.ngOnInit(),this.setupA11yAttributes()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelEditHereComponent ngOnInit: ",e)}}ngOnDestroy(){try{super.ngOnDestroy()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelEditHereComponent ngOnDestroy: ",e)}}setupA11yAttributes(){try{this.elementRef.nativeElement.setAttribute("data-testid",this.componentId+"-container")}catch(e){this.loggingService.catch("Error in SingleEditorModePanelEditHereComponent setupA11yAttributes:",e)}}};r.\u0275fac=function(t){return new(t||r)(E(F),E(U),E(c))},r.\u0275cmp=q({type:r,selectors:[["velt-single-editor-mode-panel-edit-here"]],standalone:!1,features:[$],decls:1,vars:1,consts:[[4,"ngIf"],[4,"veltIf"],["class","velt-single-editor-mode-panel-btn follow-btn","data-velt-ignore","",3,"click",4,"ngIf"],["data-velt-ignore","",1,"velt-single-editor-mode-panel-btn","follow-btn",3,"click"],[4,"veltDynamicTemplate"]],template:function(t,i){t&1&&S(0,xi,2,6,"ng-container",0),t&2&&v("ngIf",i.componentConfigSignal())},dependencies:[B,V,W,re],styles:["html[_ngcontent-%COMP%]{--velt-base-rem-unit: 1}*[data-snippyly-element=true][_ngcontent-%COMP%], *[data-velt-element=true][_ngcontent-%COMP%]{font-family:var(--velt-default-font-family)}velt-wireframe[_ngcontent-%COMP%]{display:none!important}body.velt-pin-dragging[_ngcontent-%COMP%] iframe[_ngcontent-%COMP%]{pointer-events:none!important}[_nghost-%COMP%]:empty{display:none}.velt-single-editor-mode-panel-btn[_ngcontent-%COMP%]{background-color:var(--velt-background-3);color:var(--velt-text-0);padding:var(--velt-spacing-sm) var(--velt-spacing-md);border-radius:var(--velt-border-radius-full);display:inline-flex;justify-content:center;align-items:center;border:none;font-weight:600;font-size:var(--velt-font-size-sm);cursor:pointer;pointer-events:all}.velt-single-editor-mode-panel-btn[_ngcontent-%COMP%]:hover{transition:background-color .5s;background-color:var(--velt-background-5)}"],changeDetection:0});let n=r;return n})();var ni=n=>({componentConfigSignal:n}),Ri=(n,r)=>({condition:n,data:r}),Ni=(n,r,o,e,t)=>({template:n,context:r,componentName:"velt-single-editor-mode-panel-editor-text-wireframe",variant:o,setIfCondition:e,componentElementRef:t});function Pi(n,r){if(n&1&&(b(0),X(1),J(2,"translate"),J(3,"translate"),J(4,"translate"),_()),n&2){let o=g(3).ngIf;h(),Z(" ",o.requestEditorAccessCountdown?((o.singleEditorLiveStateData==null||o.singleEditorLiveStateData.requestEditorAccess==null||o.singleEditorLiveStateData.requestEditorAccess.user==null?null:o.singleEditorLiveStateData.requestEditorAccess.user.name)||(o.singleEditorLiveStateData==null||o.singleEditorLiveStateData.requestEditorAccess==null||o.singleEditorLiveStateData.requestEditorAccess.user==null?null:o.singleEditorLiveStateData.requestEditorAccess.user.email))+" "+z(2,1,"requested edit access."):!(o.singleEditorConfig!=null&&o.singleEditorConfig.singleTabEditor)||o.isUserEditor!=null&&o.isUserEditor.isEditorOnCurrentTab?z(3,3,"You are editing."):z(4,5,"You are editing on different tab.")," ")}}function wi(n,r){if(n&1&&(R(0,"span",3),S(1,Pi,5,7,"ng-container",4),N()),n&2){let o=g(2).ngIf,e=g();h(),v("veltDynamicTemplate",G(3,Ni,e.template,x(1,ni,e.componentConfigSignal),o==null?null:o.variant,e.setIfCondition.bind(e),e.elementRef))}}function ki(n,r){if(n&1&&(b(0),S(1,wi,2,9,"span",2),_()),n&2){let o=g().ngIf;h(),v("ngIf",o.type==="editor")}}function Fi(n,r){if(n&1&&(b(0),S(1,ki,2,1,"ng-container",1),_()),n&2){let o=g();h(),v("veltIf",j(3,Ri,o.conditionSignal(),x(1,ni,o.componentConfigSignal)))}}var Re=(()=>{let r=class r extends te{constructor(e,t,i){super(e,t,i),this.elementRef=e,this.dynamicDataService=t,this.loggingService=i,this.componentId="velt-single-editor-mode-panel-editor-text";try{super.initializeComponentConfigSignal(new H)}catch(s){this.loggingService.catch("Error in SingleEditorModePanelEditorTextComponent constructor:",s)}}ngOnInit(){try{super.ngOnInit(),this.setupA11yAttributes()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelEditorTextComponent ngOnInit: ",e)}}ngOnDestroy(){try{super.ngOnDestroy()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelEditorTextComponent ngOnDestroy: ",e)}}setupA11yAttributes(){try{this.elementRef.nativeElement.setAttribute("data-testid",this.componentId+"-container")}catch(e){this.loggingService.catch("Error in SingleEditorModePanelEditorTextComponent setupA11yAttributes:",e)}}};r.\u0275fac=function(t){return new(t||r)(E(F),E(U),E(c))},r.\u0275cmp=q({type:r,selectors:[["velt-single-editor-mode-panel-editor-text"]],standalone:!1,features:[$],decls:1,vars:1,consts:[[4,"ngIf"],[4,"veltIf"],["class","velt-single-editor-mode-panel-text follow-text","data-velt-ignore","",4,"ngIf"],["data-velt-ignore","",1,"velt-single-editor-mode-panel-text","follow-text"],[4,"veltDynamicTemplate"]],template:function(t,i){t&1&&S(0,Fi,2,6,"ng-container",0),t&2&&v("ngIf",i.componentConfigSignal())},dependencies:[B,V,W,re],styles:["[_nghost-%COMP%]:empty{display:none}"],changeDetection:0});let n=r;return n})();var ri=n=>({componentConfigSignal:n}),$i=(n,r)=>({condition:n,data:r}),Bi=(n,r,o,e,t)=>({template:n,context:r,componentName:"velt-single-editor-mode-panel-viewer-text-wireframe",variant:o,setIfCondition:e,componentElementRef:t});function ji(n,r){if(n&1&&(b(0),X(1),J(2,"translate"),_()),n&2){let o=g(3).ngIf;h(),Z(" ",o.leaderName+" "+z(2,1,"is editing.")," ")}}function Gi(n,r){if(n&1&&(R(0,"span",3),S(1,ji,3,3,"ng-container",4),N()),n&2){let o=g(2).ngIf,e=g();h(),v("veltDynamicTemplate",G(3,Bi,e.template,x(1,ri,e.componentConfigSignal),o==null?null:o.variant,e.setIfCondition.bind(e),e.elementRef))}}function Wi(n,r){if(n&1&&(b(0),S(1,Gi,2,9,"span",2),_()),n&2){let o=g().ngIf;h(),v("ngIf",o.type==="reader")}}function Vi(n,r){if(n&1&&(b(0),S(1,Wi,2,1,"ng-container",1),_()),n&2){let o=g();h(),v("veltIf",j(3,$i,o.conditionSignal(),x(1,ri,o.componentConfigSignal)))}}var Ne=(()=>{let r=class r extends te{constructor(e,t,i){super(e,t,i),this.elementRef=e,this.dynamicDataService=t,this.loggingService=i,this.componentId="velt-single-editor-mode-panel-viewer-text";try{super.initializeComponentConfigSignal(new H)}catch(s){this.loggingService.catch("Error in SingleEditorModePanelViewerTextComponent constructor:",s)}}ngOnInit(){try{super.ngOnInit(),this.setupA11yAttributes()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelViewerTextComponent ngOnInit: ",e)}}ngOnDestroy(){try{super.ngOnDestroy()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelViewerTextComponent ngOnDestroy: ",e)}}setupA11yAttributes(){try{this.elementRef.nativeElement.setAttribute("data-testid",this.componentId+"-container")}catch(e){this.loggingService.catch("Error in SingleEditorModePanelViewerTextComponent setupA11yAttributes:",e)}}};r.\u0275fac=function(t){return new(t||r)(E(F),E(U),E(c))},r.\u0275cmp=q({type:r,selectors:[["velt-single-editor-mode-panel-viewer-text"]],standalone:!1,features:[$],decls:1,vars:1,consts:[[4,"ngIf"],[4,"veltIf"],["class","velt-single-editor-mode-panel-text follow-text","data-velt-ignore","",4,"ngIf"],["data-velt-ignore","",1,"velt-single-editor-mode-panel-text","follow-text"],[4,"veltDynamicTemplate"]],template:function(t,i){t&1&&S(0,Vi,2,6,"ng-container",0),t&2&&v("ngIf",i.componentConfigSignal())},dependencies:[B,V,W,re],styles:["[_nghost-%COMP%]:empty{display:none}"],changeDetection:0});let n=r;return n})();var oi=n=>({componentConfigSignal:n}),Ji=(n,r)=>({condition:n,data:r}),zi=(n,r,o,e,t)=>({template:n,context:r,componentName:"velt-single-editor-mode-panel-reject-request-wireframe",variant:o,setIfCondition:e,componentElementRef:t});function Ki(n,r){n&1&&(b(0),X(1),J(2,"translate"),_()),n&2&&(h(),Z(" ",z(2,1,"Reject Request")," "))}function Qi(n,r){if(n&1){let o=ge();R(0,"button",3),ue("click",function(){le(o);let t=g(2).ngIf;return de(t.rejectEditorAccessRequest())}),S(1,Ki,3,3,"ng-container",4),N()}if(n&2){let o=g(2).ngIf,e=g();h(),v("veltDynamicTemplate",G(3,zi,e.template,x(1,oi,e.componentConfigSignal),o==null?null:o.variant,e.setIfCondition.bind(e),e.elementRef))}}function Yi(n,r){if(n&1&&(b(0),S(1,Qi,2,9,"button",2),_()),n&2){let o=g().ngIf;h(),v("ngIf",o.type==="editor"&&o.requestEditorAccessCountdown)}}function Xi(n,r){if(n&1&&(b(0),S(1,Yi,2,1,"ng-container",1),_()),n&2){let o=g();h(),v("veltIf",j(3,Ji,o.conditionSignal(),x(1,oi,o.componentConfigSignal)))}}var Pe=(()=>{let r=class r extends te{constructor(e,t,i){super(e,t,i),this.elementRef=e,this.dynamicDataService=t,this.loggingService=i,this.componentId="velt-single-editor-mode-panel-reject-request";try{super.initializeComponentConfigSignal(new H)}catch(s){this.loggingService.catch("Error in SingleEditorModePanelRejectRequestComponent constructor:",s)}}ngOnInit(){try{super.ngOnInit(),this.setupA11yAttributes()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelRejectRequestComponent ngOnInit: ",e)}}ngOnDestroy(){try{super.ngOnDestroy()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelRejectRequestComponent ngOnDestroy: ",e)}}setupA11yAttributes(){try{this.elementRef.nativeElement.setAttribute("data-testid",this.componentId+"-container")}catch(e){this.loggingService.catch("Error in SingleEditorModePanelRejectRequestComponent setupA11yAttributes:",e)}}};r.\u0275fac=function(t){return new(t||r)(E(F),E(U),E(c))},r.\u0275cmp=q({type:r,selectors:[["velt-single-editor-mode-panel-reject-request"]],standalone:!1,features:[$],decls:1,vars:1,consts:[[4,"ngIf"],[4,"veltIf"],["class","velt-single-editor-mode-panel-btn follow-btn","data-velt-ignore","",3,"click",4,"ngIf"],["data-velt-ignore","",1,"velt-single-editor-mode-panel-btn","follow-btn",3,"click"],[4,"veltDynamicTemplate"]],template:function(t,i){t&1&&S(0,Xi,2,6,"ng-container",0),t&2&&v("ngIf",i.componentConfigSignal())},dependencies:[B,V,W,re],styles:["html[_ngcontent-%COMP%]{--velt-base-rem-unit: 1}*[data-snippyly-element=true][_ngcontent-%COMP%], *[data-velt-element=true][_ngcontent-%COMP%]{font-family:var(--velt-default-font-family)}velt-wireframe[_ngcontent-%COMP%]{display:none!important}body.velt-pin-dragging[_ngcontent-%COMP%] iframe[_ngcontent-%COMP%]{pointer-events:none!important}[_nghost-%COMP%]:empty{display:none}.velt-single-editor-mode-panel-btn[_ngcontent-%COMP%]{background-color:var(--velt-background-3);color:var(--velt-text-0);padding:var(--velt-spacing-sm) var(--velt-spacing-md);border-radius:var(--velt-border-radius-full);display:inline-flex;justify-content:center;align-items:center;border:none;font-weight:600;font-size:var(--velt-font-size-sm);cursor:pointer;pointer-events:all}.velt-single-editor-mode-panel-btn[_ngcontent-%COMP%]:hover{transition:background-color .5s;background-color:var(--velt-background-5)}"],changeDetection:0});let n=r;return n})();var si=n=>({componentConfigSignal:n}),en=(n,r)=>({condition:n,data:r}),tn=(n,r,o,e,t)=>({template:n,context:r,componentName:"velt-single-editor-mode-panel-request-access-wireframe",variant:o,setIfCondition:e,componentElementRef:t});function nn(n,r){if(n&1&&(b(0),X(1),J(2,"translate"),J(3,"translate"),_()),n&2){let o=g(3).ngIf;h(),Z(" ",o.editAccessRequested?z(2,1,"Access Requested"):z(3,3,"Request access")," ")}}function rn(n,r){if(n&1){let o=ge();R(0,"button",3),ue("click",function(){le(o);let t=g(2).ngIf;return de(t.requestEditorAccess())}),S(1,nn,4,5,"ng-container",4),N()}if(n&2){let o=g(2).ngIf,e=g();h(),v("veltDynamicTemplate",G(3,tn,e.template,x(1,si,e.componentConfigSignal),o==null?null:o.variant,e.setIfCondition.bind(e),e.elementRef))}}function on(n,r){if(n&1&&(b(0),S(1,rn,2,9,"button",2),_()),n&2){let o=g().ngIf;h(),v("ngIf",o.type!=="editor")}}function sn(n,r){if(n&1&&(b(0),S(1,on,2,1,"ng-container",1),_()),n&2){let o=g();h(),v("veltIf",j(3,en,o.conditionSignal(),x(1,si,o.componentConfigSignal)))}}var we=(()=>{let r=class r extends te{constructor(e,t,i){super(e,t,i),this.elementRef=e,this.dynamicDataService=t,this.loggingService=i,this.componentId="velt-single-editor-mode-panel-request-access";try{super.initializeComponentConfigSignal(new H)}catch(s){this.loggingService.catch("Error in SingleEditorModePanelRequestAccessComponent constructor:",s)}}ngOnInit(){try{super.ngOnInit(),this.setupA11yAttributes()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelRequestAccessComponent ngOnInit: ",e)}}ngOnDestroy(){try{super.ngOnDestroy()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelRequestAccessComponent ngOnDestroy: ",e)}}setupA11yAttributes(){try{this.elementRef.nativeElement.setAttribute("data-testid",this.componentId+"-container")}catch(e){this.loggingService.catch("Error in SingleEditorModePanelRequestAccessComponent setupA11yAttributes:",e)}}};r.\u0275fac=function(t){return new(t||r)(E(F),E(U),E(c))},r.\u0275cmp=q({type:r,selectors:[["velt-single-editor-mode-panel-request-access"]],standalone:!1,features:[$],decls:1,vars:1,consts:[[4,"ngIf"],[4,"veltIf"],["class","velt-single-editor-mode-panel-btn follow-btn","data-velt-ignore","",3,"click",4,"ngIf"],["data-velt-ignore","",1,"velt-single-editor-mode-panel-btn","follow-btn",3,"click"],[4,"veltDynamicTemplate"]],template:function(t,i){t&1&&S(0,sn,2,6,"ng-container",0),t&2&&v("ngIf",i.componentConfigSignal())},dependencies:[B,V,W,re],styles:["html[_ngcontent-%COMP%]{--velt-base-rem-unit: 1}*[data-snippyly-element=true][_ngcontent-%COMP%], *[data-velt-element=true][_ngcontent-%COMP%]{font-family:var(--velt-default-font-family)}velt-wireframe[_ngcontent-%COMP%]{display:none!important}body.velt-pin-dragging[_ngcontent-%COMP%] iframe[_ngcontent-%COMP%]{pointer-events:none!important}[_nghost-%COMP%]:empty{display:none}.velt-single-editor-mode-panel-btn[_ngcontent-%COMP%]{background-color:var(--velt-background-3);color:var(--velt-text-0);padding:var(--velt-spacing-sm) var(--velt-spacing-md);border-radius:var(--velt-border-radius-full);display:inline-flex;justify-content:center;align-items:center;border:none;font-weight:600;font-size:var(--velt-font-size-sm);cursor:pointer;pointer-events:all}.velt-single-editor-mode-panel-btn[_ngcontent-%COMP%]:hover{transition:background-color .5s;background-color:var(--velt-background-5)}"],changeDetection:0});let n=r;return n})();var dt=n=>({componentConfigSignal:n}),ai=(n,r)=>({condition:n,data:r}),ln=(n,r,o,e,t)=>({template:n,context:r,componentName:"velt-single-editor-mode-panel-wireframe",variant:o,setIfCondition:e,componentElementRef:t});function dn(n,r){n&1&&yt(0)}function gn(n,r){if(n&1&&(R(0,"velt-shadow-dom-internal"),S(1,dn,1,0,"ng-container",4),N()),n&2){g(3);let o=at(2);h(),v("ngTemplateOutlet",o)}}function un(n,r){if(n&1&&(b(0),S(1,gn,2,1,"velt-shadow-dom-internal",3),_()),n&2){let o=g().ngIf,e=g(),t=at(2);h(),v("ngIf",o.shadowDom&&!e.template||e.template&&e.isExplicitShadowDom)("ngIfElse",t)}}function vn(n,r){if(n&1&&(b(0),S(1,un,2,2,"ng-container",2),_()),n&2){let o=g();h(),v("veltIf",j(3,ai,o.conditionSignal(),x(1,dt,o.componentConfigSignal)))}}function mn(n,r){if(n&1&&(b(0),R(1,"div",8),Ve(2,"velt-single-editor-mode-panel-viewer-text",9)(3,"velt-single-editor-mode-panel-editor-text",9)(4,"velt-single-editor-mode-panel-countdown",9)(5,"velt-single-editor-mode-panel-request-access",9)(6,"velt-single-editor-mode-panel-reject-request",9)(7,"velt-single-editor-mode-panel-edit-here",9),N(),_()),n&2){let o=g(6);h(2),v("componentConfigSignal",o.componentConfigSignal),h(),v("componentConfigSignal",o.componentConfigSignal),h(),v("componentConfigSignal",o.componentConfigSignal),h(),v("componentConfigSignal",o.componentConfigSignal),h(),v("componentConfigSignal",o.componentConfigSignal),h(),v("componentConfigSignal",o.componentConfigSignal)}}function hn(n,r){if(n&1&&(b(0),S(1,mn,8,6,"ng-container",7),_()),n&2){let o=g(3).ngIf,e=g(2);h(),v("veltDynamicTemplate",G(3,ln,e.template,x(1,dt,e.componentConfigSignal),o==null?null:o.variant,e.setIfCondition.bind(e),e.elementRef))}}function Sn(n,r){if(n&1&&(R(0,"div",6),S(1,hn,2,9,"ng-container",2),N()),n&2){let o=g(2).ngIf,e=g(2);Tt("velt-single-editor-mode-panel-container-no-pointer",o.type==="editor")("no-pointer",o.type==="editor"),h(),v("veltIf",j(7,ai,e.conditionSignal(),x(5,dt,e.componentConfigSignal)))}}function pn(n,r){if(n&1&&(b(0),S(1,Sn,2,10,"div",5),_()),n&2){let o=g().ngIf;h(),v("ngIf",o.leaderName!==""||o.type==="editor")}}function En(n,r){if(n&1&&(b(0),S(1,pn,2,1,"ng-container",1),_()),n&2){let o=r.ngIf;h(),v("ngIf",o.singleEditorMode)}}function fn(n,r){if(n&1&&S(0,En,2,1,"ng-container",1),n&2){let o=g();v("ngIf",o.componentConfigSignal())}}var ye=(()=>{let r=class r extends it{set _shadowDom(e){try{let t=e;typeof e=="string"&&(t=JSON.parse(e)),this.isExplicitShadowDom=!!t,this.componentConfigSignal.update(i=>(i=A(f({},i),{shadowDom:t}),i))}catch(t){this.loggingService.catch("Error in SingleEditorModePanelComponent _shadowDom: ",t)}}constructor(e,t,i,s,l,u,d){super(e,l,void 0,void 0,void 0,u,s),this.elementRef=e,this.authService=t,this.liveStateService=i,this.loggingService=s,this.themeService=l,this.dynamicDataService=u,this.wireframeService=d,this.isExplicitShadowDom=!1,this.subscriptions=[],this.componentConfigSignal=We({singleEditorMode:!1,defaultSingleEditorUIEnabled:!1,editAccessRequested:!1,leaderName:"",type:"reader",requestEditorAccessCountdown:0,singleEditorLiveStateData:null,singleEditorConfig:null,isUserEditor:null,variant:this.variant,shadowDom:!0,requestEditorAccess:this.requestEditorAccess.bind(this),cancelEditorAccessRequest:this.cancelEditorAccessRequest.bind(this),rejectEditorAccessRequest:this.rejectEditorAccessRequest.bind(this),acceptEditorAccessRequest:this.acceptEditorAccessRequest.bind(this),editCurrentTab:this.editCurrentTab.bind(this)}),this.componentId="velt-single-editor-mode-panel";try{this.loggingService.log("%c[WB] Calling FUNCTION: SingleEditorModePanelComponent constructor","color: green;"),this.subscriptions.push(this.liveStateService.getSingleEditorMode$().subscribe(a=>{this.componentConfigSignal.update(C=>A(f({},C),{singleEditorMode:a}))})),this.subscriptions.push(this.liveStateService.getDefaultSingleEditorUIEnabled$().subscribe(a=>{this.componentConfigSignal.update(C=>A(f({},C),{defaultSingleEditorUIEnabled:a}))})),this.subscriptions.push(this.liveStateService.getSingleEditorModeConfig$().subscribe(a=>{this.componentConfigSignal.update(C=>A(f({},C),{singleEditorConfig:a}))})),this.subscriptions.push(this.liveStateService.isUserEditor$().subscribe(a=>{this.componentConfigSignal.update(C=>A(f({},C),{isUserEditor:a}))})),this.subscriptions.push(this.liveStateService.getSingleEditorLiveStateData$().subscribe(a=>{let C=this.componentConfigSignal().singleEditorLiveStateData?.requestEditorAccess?.user?.userId,P=a?.requestEditorAccess?.user?.userId;if(C&&P&&C!==P&&this.componentConfigSignal().requestEditorAccessCountdown&&this.removeRequestEditorAccessCountdown(),this.componentConfigSignal.update(O=>A(f({},O),{singleEditorLiveStateData:a})),a){this.componentConfigSignal.update(w=>A(f({},w),{leaderName:a?.editor?.name||a?.editor?.email||""}));let O=this.authService.getUser();O?.userId===a?.editor?.userId?this.componentConfigSignal.update(w=>A(f({},w),{type:"editor"})):this.componentConfigSignal.update(w=>A(f({},w),{type:"reader"})),O?.userId===a?.requestEditorAccess?.user?.userId&&a?.requestEditorAccess?.status==="pending"?this.componentConfigSignal.update(w=>A(f({},w),{editAccessRequested:!0})):this.componentConfigSignal.update(w=>A(f({},w),{editAccessRequested:!1})),this.componentConfigSignal().type==="editor"&&!this.componentConfigSignal().requestEditorAccessCountdown&&a?.requestEditorAccess?.status==="pending"?this.showRequestEditorAccessCountdown():this.removeRequestEditorAccessCountdown()}}))}catch(a){this.loggingService.catch("Error in SingleEditorModePanelComponent constructor: ",a)}}ngOnInit(){try{this.loggingService.log("%c[WB] Calling FUNCTION: ngOnInit","color: green;"),super.ngOnInit(),this.setupA11yAttributes();let e="velt-single-editor-mode-panel-wireframe";this.variant&&(e+=`---${this.variant}`),this.wireframeService.getWireframe$(e).subscribe(t=>{if(t){let i=document.createElement(t.tagName);i.innerHTML=t.innerHTML,this.template=i}})}catch(e){this.loggingService.catch("Error in SingleEditorModePanelComponent ngOnInit: ",e)}}ngOnDestroy(){try{super.ngOnDestroy(),this.subscriptions.forEach(e=>{e.unsubscribe()})}catch(e){this.loggingService.catch("Error in SingleEditorModePanelComponent ngOnDestroy: ",e)}}ngOnChanges(e){try{super.ngOnChanges(e),e&&Object.keys(e).forEach(t=>{this.componentConfigSignal.update(i=>(i=A(f({},i),{[t]:e[t].currentValue}),i))})}catch(t){this.loggingService.catch("Error in SingleEditorModePanelComponent ngOnChanges: ",t)}}setupA11yAttributes(){try{this.elementRef.nativeElement.setAttribute("data-testid",this.componentId+"-container")}catch(e){this.loggingService.catch("Error in SingleEditorModePanelComponent setupA11yAttributes:",e)}}showRequestEditorAccessCountdown(){try{this.loggingService.log("%c[WB] Calling FUNCTION: showRequestEditorAccessCountdown","color: green;"),this.componentConfigSignal.update(e=>(e=A(f({},e),{requestEditorAccessCountdown:e.singleEditorLiveStateData?.requestEditorAccess?.editorAccessTimeout||ee.LIVE_STATE_REQUEST_EDITOR_ACCESS_WAIT_TIME}),e)),this.interval=setInterval(()=>{this.componentConfigSignal.update(e=>A(f({},e),{requestEditorAccessCountdown:e.requestEditorAccessCountdown-1})),this.componentConfigSignal().requestEditorAccessCountdown<=0&&clearInterval(this.interval)},1e3)}catch(e){this.loggingService.catch("Error in SingleEditorModePanelComponent showRequestEditorAccessCountdown: ",e)}}removeRequestEditorAccessCountdown(){try{this.loggingService.log("%c[WB] Calling FUNCTION: removeRequestEditorAccessCountdown","color: green;"),this.componentConfigSignal.update(e=>A(f({},e),{requestEditorAccessCountdown:0})),clearInterval(this.interval)}catch(e){this.loggingService.catch("Error in SingleEditorModePanelComponent removeRequestEditorAccessCountdown: ",e)}}requestEditorAccess(){try{this.loggingService.log("%c[WB] Calling FUNCTION: requestEditorAccess","color: green;"),this.componentConfigSignal().editAccessRequested||this.liveStateService.requestEditorAccess().subscribe()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelComponent requestEditorAccess: ",e)}}cancelEditorAccessRequest(){try{this.loggingService.log("%c[WB] Calling FUNCTION: cancelEditorAccessRequest","color: green;"),this.liveStateService.cancelEditorAccessRequest()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelComponent cancelEditorAccessRequest: ",e)}}acceptEditorAccessRequest(){try{this.loggingService.log("%c[WB] Calling FUNCTION: acceptEditorAccessRequest","color: green;"),this.liveStateService.acceptEditorAccessRequest()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelComponent acceptEditorAccessRequest: ",e)}}rejectEditorAccessRequest(){try{this.loggingService.log("%c[WB] Calling FUNCTION: rejectEditorAccessRequest","color: green;"),this.liveStateService.rejectEditorAccessRequest()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelComponent rejectEditorAccessRequest: ",e)}}editCurrentTab(){try{this.loggingService.log("%c[WB] Calling FUNCTION: editCurrentTab","color: green;"),this.liveStateService.editCurrentTab()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelComponent editCurrentTab: ",e)}}};r.\u0275fac=function(t){return new(t||r)(E(F),E(Oe),E(T),E(c),E(tt),E(U),E(Wt))},r.\u0275cmp=q({type:r,selectors:[["velt-single-editor-mode-panel"]],inputs:{variant:"variant",_shadowDom:[0,"shadowDom","_shadowDom"]},standalone:!1,features:[He([U]),$,bt],decls:3,vars:1,consts:[["liveStateSyncPanelRef",""],[4,"ngIf"],[4,"veltIf"],[4,"ngIf","ngIfElse"],[4,"ngTemplateOutlet"],["data-velt-ignore","","class","velt-single-editor-mode-panel-container single-editor-mode-panel-container",3,"velt-single-editor-mode-panel-container-no-pointer","no-pointer",4,"ngIf"],["data-velt-ignore","",1,"velt-single-editor-mode-panel-container","single-editor-mode-panel-container"],[4,"veltDynamicTemplate"],["data-velt-ignore","",1,"velt-single-editor-mode-panel","follow-dialog"],[3,"componentConfigSignal"]],template:function(t,i){t&1&&S(0,vn,2,6,"ng-container",1)(1,fn,1,1,"ng-template",null,0,At),t&2&&v("ngIf",i.componentConfigSignal())},dependencies:[B,Dt,V,W,Ht,xe,Ue,Re,Ne,Pe,we],styles:["html[_ngcontent-%COMP%]{--velt-base-rem-unit: 1}*[data-snippyly-element=true][_ngcontent-%COMP%], *[data-velt-element=true][_ngcontent-%COMP%]{font-family:var(--velt-default-font-family)}velt-wireframe[_ngcontent-%COMP%]{display:none!important}body.velt-pin-dragging[_ngcontent-%COMP%] iframe[_ngcontent-%COMP%]{pointer-events:none!important}[_nghost-%COMP%]{--velt-green: var(--velt-light-mode-green);--velt-magenta: var(--velt-light-mode-magenta);--velt-amber: var(--velt-light-mode-amber);--velt-purple: var(--velt-light-mode-purple);--velt-cyan: var(--velt-light-mode-cyan);--velt-orange: var(--velt-light-mode-orange);--velt-black: var(--velt-light-mode-black);--velt-white: var(--velt-light-mode-white);--velt-gray: var(--velt-light-mode-gray);--velt-error: var(--velt-light-mode-error);--velt-error-hover: var(--velt-light-mode-error-hover);--velt-error-foreground: var(--velt-light-mode-error-foreground);--velt-error-light: var(--velt-light-mode-error-light);--velt-error-transparent: var(--velt-light-mode-error-transparent);--velt-warning: var(--velt-light-mode-warning);--velt-warning-hover: var(--velt-light-mode-warning-hover);--velt-warning-foreground: var(--velt-light-mode-warning-foreground);--velt-warning-light: var(--velt-light-mode-warning-light);--velt-warning-transparent: var(--velt-light-mode-warning-transparent);--velt-agent-accent: #4495ff;--velt-agent-accent-transparent: rgba(68, 149, 255, .2);--velt-success: var(--velt-light-mode-success);--velt-success-hover: var(--velt-light-mode-success-hover);--velt-success-foreground: var(--velt-light-mode-success-foreground);--velt-success-light: var(--velt-light-mode-success-light);--velt-success-transparent: var(--velt-light-mode-success-transparent);--velt-accent: var(--velt-light-mode-accent);--velt-accent-text: var(--velt-light-mode-accent-text);--velt-accent-hover: var(--velt-light-mode-accent-hover);--velt-accent-foreground: var(--velt-light-mode-accent-foreground);--velt-accent-light: var(--velt-light-mode-accent-light);--velt-accent-transparent: var(--velt-light-mode-accent-transparent);--velt-text-0: var(--velt-light-mode-text-0);--velt-text-1: var(--velt-light-mode-text-1);--velt-text-2: var(--velt-light-mode-text-2);--velt-text-3: var(--velt-light-mode-text-3);--velt-text-4: var(--velt-light-mode-text-4);--velt-text-5: var(--velt-light-mode-text-5);--velt-text-6: var(--velt-light-mode-text-6);--velt-text-7: var(--velt-light-mode-text-7);--velt-text-8: var(--velt-light-mode-text-8);--velt-text-9: var(--velt-light-mode-text-9);--velt-text-10: var(--velt-light-mode-text-10);--velt-text-11: var(--velt-light-mode-text-11);--velt-text-12: var(--velt-light-mode-text-12);--velt-background-0: var(--velt-light-mode-background-0);--velt-background-1: var(--velt-light-mode-background-1);--velt-background-2: var(--velt-light-mode-background-2);--velt-background-3: var(--velt-light-mode-background-3);--velt-background-4: var(--velt-light-mode-background-4);--velt-background-5: var(--velt-light-mode-background-5);--velt-background-6: var(--velt-light-mode-background-6);--velt-background-7: var(--velt-light-mode-background-7);--velt-background-8: var(--velt-light-mode-background-8);--velt-background-9: var(--velt-light-mode-background-9);--velt-background-10: var(--velt-light-mode-background-10);--velt-border-0: var(--velt-light-mode-border-0);--velt-border-1: var(--velt-light-mode-border-1);--velt-border-2: var(--velt-light-mode-border-2);--velt-border-3: var(--velt-light-mode-border-3);--velt-border-4: var(--velt-light-mode-border-4);--velt-border-5: var(--velt-light-mode-border-5);--velt-border-6: var(--velt-light-mode-border-6);--velt-border-7: var(--velt-light-mode-border-7);--velt-border-8: var(--velt-light-mode-border-8);--velt-border-9: var(--velt-light-mode-border-9);--velt-border-10: var(--velt-light-mode-border-10);--velt-background-transparent: var(--velt-light-mode-background-transparent);--velt-border-transparent: var(--velt-light-mode-border-transparent);--velt-animation-transparent: var(--velt-light-mode-animation-transparent)}[_nghost-%COMP%]:empty{display:none}[dark][_nghost-%COMP%]{--velt-green: var(--velt-dark-mode-green);--velt-magenta: var(--velt-dark-mode-magenta);--velt-amber: var(--velt-dark-mode-amber);--velt-purple: var(--velt-dark-mode-purple);--velt-cyan: var(--velt-dark-mode-cyan);--velt-orange: var(--velt-dark-mode-orange);--velt-black: var(--velt-dark-mode-black);--velt-white: var(--velt-dark-mode-white);--velt-gray: var(--velt-dark-mode-gray);--velt-error: var(--velt-dark-mode-error);--velt-error-hover: var(--velt-dark-mode-error-hover);--velt-error-foreground: var(--velt-dark-mode-error-foreground);--velt-error-light: var(--velt-dark-mode-error-light);--velt-error-transparent: var(--velt-dark-mode-error-transparent);--velt-warning: var(--velt-dark-mode-warning);--velt-warning-hover: var(--velt-dark-mode-warning-hover);--velt-warning-foreground: var(--velt-dark-mode-warning-foreground);--velt-warning-light: var(--velt-dark-mode-warning-light);--velt-warning-transparent: var(--velt-dark-mode-warning-transparent);--velt-agent-accent: #4495ff;--velt-agent-accent-transparent: rgba(68, 149, 255, .2);--velt-success: var(--velt-dark-mode-success);--velt-success-hover: var(--velt-dark-mode-success-hover);--velt-success-foreground: var(--velt-dark-mode-success-foreground);--velt-success-light: var(--velt-dark-mode-success-light);--velt-success-transparent: var(--velt-dark-mode-success-transparent);--velt-accent: var(--velt-dark-mode-accent);--velt-accent-text: var(--velt-dark-mode-accent-text);--velt-accent-hover: var(--velt-dark-mode-accent-hover);--velt-accent-foreground: var(--velt-dark-mode-accent-foreground);--velt-accent-light: var(--velt-dark-mode-accent-light);--velt-accent-transparent: var(--velt-dark-mode-accent-transparent);--velt-text-0: var(--velt-dark-mode-text-0);--velt-text-1: var(--velt-dark-mode-text-1);--velt-text-2: var(--velt-dark-mode-text-2);--velt-text-3: var(--velt-dark-mode-text-3);--velt-text-4: var(--velt-dark-mode-text-4);--velt-text-5: var(--velt-dark-mode-text-5);--velt-text-6: var(--velt-dark-mode-text-6);--velt-text-7: var(--velt-dark-mode-text-7);--velt-text-8: var(--velt-dark-mode-text-8);--velt-text-9: var(--velt-dark-mode-text-9);--velt-text-10: var(--velt-dark-mode-text-10);--velt-text-11: var(--velt-dark-mode-text-11);--velt-text-12: var(--velt-dark-mode-text-12);--velt-background-0: var(--velt-dark-mode-background-0);--velt-background-1: var(--velt-dark-mode-background-1);--velt-background-2: var(--velt-dark-mode-background-2);--velt-background-3: var(--velt-dark-mode-background-3);--velt-background-4: var(--velt-dark-mode-background-4);--velt-background-5: var(--velt-dark-mode-background-5);--velt-background-6: var(--velt-dark-mode-background-6);--velt-background-7: var(--velt-dark-mode-background-7);--velt-background-8: var(--velt-dark-mode-background-8);--velt-background-9: var(--velt-dark-mode-background-9);--velt-background-10: var(--velt-dark-mode-background-10);--velt-border-0: var(--velt-dark-mode-border-0);--velt-border-1: var(--velt-dark-mode-border-1);--velt-border-2: var(--velt-dark-mode-border-2);--velt-border-3: var(--velt-dark-mode-border-3);--velt-border-4: var(--velt-dark-mode-border-4);--velt-border-5: var(--velt-dark-mode-border-5);--velt-border-6: var(--velt-dark-mode-border-6);--velt-border-7: var(--velt-dark-mode-border-7);--velt-border-8: var(--velt-dark-mode-border-8);--velt-border-9: var(--velt-dark-mode-border-9);--velt-border-10: var(--velt-dark-mode-border-10);--velt-background-transparent: var(--velt-dark-mode-background-transparent);--velt-border-transparent: var(--velt-dark-mode-border-transparent);--velt-animation-transparent: var(--velt-dark-mode-animation-transparent)}.velt-single-editor-mode-panel[_ngcontent-%COMP%]{font-size:var(--velt-font-size-xs);display:flex;justify-content:center;align-items:center;gap:var(--velt-spacing-sm);width:fit-content;padding:var(--velt-spacing-sm) var(--velt-spacing-md);background-color:var(--velt-background-0);color:var(--velt-text-0);border-radius:var(--velt-border-radius-full);box-shadow:0 8px 16px -8px #0f0f0f1a;border:1px solid var(--velt-border-4)}.velt-single-editor-mode-panel-container.velt-single-editor-mode-panel-container-no-pointer[_ngcontent-%COMP%]{pointer-events:none}"],changeDetection:0});let n=r;return n})();function bn(n,r){if(n&1&&(b(0),R(1,"div",1),Ve(2,"velt-single-editor-mode-panel",2),N(),_()),n&2){let o=g(2);h(2),v("variant",o.variant)}}function _n(n,r){if(n&1&&(b(0),S(1,bn,3,1,"ng-container",0),_()),n&2){let o=r.ngIf;h(),v("ngIf",o.singleEditorMode&&o.defaultSingleEditorUIEnabled)}}var gt=(()=>{let r=class r extends it{constructor(e,t,i,s,l,u){super(e,t,void 0,void 0,void 0,i,s),this.elementRef=e,this.themeService=t,this.dynamicDataService=i,this.loggingService=s,this.liveStateService=l,this.domService=u,this.subscriptions=[],this.componentConfigSignal=We({singleEditorMode:!1,defaultSingleEditorUIEnabled:!1,variant:this.variant}),this.componentId="velt-live-state-sync-overlay";try{this.subscriptions.push(this.liveStateService.getSingleEditorMode$().subscribe(d=>{this.componentConfigSignal.update(a=>A(f({},a),{singleEditorMode:d}))})),this.subscriptions.push(this.liveStateService.getDefaultSingleEditorUIEnabled$().subscribe(d=>{this.componentConfigSignal.update(a=>A(f({},a),{defaultSingleEditorUIEnabled:d}))}))}catch(d){this.loggingService.catch("Error in LiveStateSyncOverlayComponent constructor: ",d)}}ngOnInit(){try{super.ngOnInit(),this.setupA11yAttributes()}catch(e){this.loggingService.catch("Error in LiveStateSyncOverlayComponent ngOnInit: ",e)}}ngAfterViewInit(){try{this.subscriptions.push(this.domService.subscribeInjectCustomCss(this.elementRef))}catch(e){this.loggingService.catch("Error in LiveStateSyncOverlayComponent ngAfterViewInit: ",e)}}ngOnDestroy(){try{super.ngOnDestroy(),this.subscriptions.forEach(e=>e.unsubscribe())}catch(e){this.loggingService.catch("Error in LiveStateSyncOverlayComponent ngOnDestroy: ",e)}}setupA11yAttributes(){try{let e=this.elementRef.nativeElement;e.setAttribute("role","dialog"),e.setAttribute("aria-labelledby",this.componentId),e.setAttribute("aria-modal","true")}catch(e){this.loggingService.catch("Error in LiveStateSyncOverlayComponent setupA11yAttributes: ",e)}}};r.\u0275fac=function(t){return new(t||r)(E(F),E(tt),E(U),E(c),E(T),E(De))},r.\u0275cmp=q({type:r,selectors:[["snippyly-live-state-sync-overlay"]],inputs:{variant:"variant"},standalone:!1,features:[He([U]),$],decls:1,vars:1,consts:[[4,"ngIf"],["data-velt-ignore","",1,"velt-live-state-sync-overlay-container","live-state-sync-overlay-container"],[3,"variant"]],template:function(t,i){t&1&&S(0,_n,2,1,"ng-container",0),t&2&&v("ngIf",i.componentConfigSignal())},dependencies:[B,ye],styles:[`html{--velt-base-rem-unit: 1}*[data-snippyly-element=true],*[data-velt-element=true]{font-family:var(--velt-default-font-family)}velt-wireframe{display:none!important}body.velt-pin-dragging iframe{pointer-events:none!important}.velt-live-state-sync-overlay-container{position:fixed;bottom:calc((2rem + 0px) * var(--velt-base-rem-unit));left:50%;transform:translate(-50%);background-color:transparent;z-index:var(--velt-live-state-sync-overlay-z-index);display:flex;justify-content:center;align-items:flex-end}
1
+ import{a as Qt}from"./chunk-HNT7HKW3.js";import{t as Jt}from"./chunk-5EO5WTC7.js";import"./chunk-ELEMLDFM.js";import"./chunk-6K2VWE4K.js";import{a as Ht}from"./chunk-APPJN3VX.js";import"./chunk-EYPJC34Q.js";import{A as W,B as V,y as Vt}from"./chunk-XYR7TNZL.js";import{a as Wt}from"./chunk-NLVNX52N.js";import{b as re}from"./chunk-S4APJ64C.js";import{a as Kt}from"./chunk-54BT4NQJ.js";import{a as zt}from"./chunk-62RN7JJN.js";import{a as Mt}from"./chunk-POME7PZR.js";import{da as U,ea as tt,fa as te,ga as it}from"./chunk-K5BJ5DAO.js";import{$ as Ae,$f as pe,$h as kt,Bf as Ie,Ch as wt,Dd as Lt,De as ee,Di as Bt,E as k,Fa as h,G as Be,Gc as B,Gi as jt,Hi as Gt,I as je,Ib as at,J as Te,Kb as Tt,L as ne,Lc as Dt,M as Et,Mf as lt,Nb as X,Nf as Qe,Pa as E,Pb as Z,Pc as Ot,Q as ft,Se as ze,T as y,Ta as _t,Te as xt,Ua as q,Va as It,W as Ge,Ya as $,Yf as Rt,_a as S,_b as He,a as f,aa as Ct,ae as Je,ai as Ye,b as A,bc as x,be as Se,bf as Ut,bh as Nt,bi as Xe,ca as L,cc as j,cf as Ke,ch as Pt,ci as c,di as Ft,fc as G,g as Q,ha as le,i as mt,ia as de,ih as Ee,ii as Ze,k as ot,kc as J,ki as De,l as Y,lb as v,lc as z,li as Oe,mb as R,nb as N,ne as ct,ob as Ve,p as st,pc as At,qa as We,qh as ae,r as p,sb as b,si as qt,t as ht,tb as _,u as St,ua as bt,ub as yt,uh as m,v as D,vb as ge,w as pt,wa as F,xb as ue,xi as $t,yi as et,z as Le,zb as g,ze as K}from"./chunk-O4F37U67.js";var nt=(()=>{let r=class r{constructor(e,t){this.analyticsService=e,this.loggingService=t,this.actionSubjects=new Map,this.subscriptions=[]}onAccessRequested(e){try{this.triggerAction(Se.ACCESS_REQUESTED,e),this.analyticsService.trackEvent(m.Events.LiveStateSync.SEM_ACCESS_REQUESTED,{viewerUserId:e?.viewer?.userId,editorUserId:e?.editor?.userId,timestamp:e?.timestamp,status:e?.status,totalUsers:e?.totalUsers,isMultipleUsersDetected:(e?.totalUsers??0)>1,presenceSnippylyUserIds:e?.presenceSnippylyUserIds,presenceClientUserIds:e?.presenceClientUserIds})}catch(t){this.loggingService.catch("Error in LiveStateActionsService onAccessRequested: ",t)}}onAccessRequestCanceled(e){try{this.triggerAction(Se.ACCESS_REQUEST_CANCELED,e),this.analyticsService.trackEvent(m.Events.LiveStateSync.SEM_ACCESS_REQUEST_CANCELED,{viewerUserId:e?.viewer?.userId,editorUserId:e?.editor?.userId,timestamp:e?.timestamp,status:e?.status,totalUsers:e?.totalUsers,isMultipleUsersDetected:(e?.totalUsers??0)>1,presenceSnippylyUserIds:e?.presenceSnippylyUserIds,presenceClientUserIds:e?.presenceClientUserIds})}catch(t){this.loggingService.catch("Error in LiveStateActionsService onAccessRequestCanceled: ",t)}}onAccessAccepted(e){try{this.triggerAction(Se.ACCESS_ACCEPTED,e),this.analyticsService.trackEvent(m.Events.LiveStateSync.SEM_ACCESS_ACCEPTED,{viewerUserId:e?.viewer?.userId,editorUserId:e?.editor?.userId,timestamp:e?.timestamp,status:e?.status,totalUsers:e?.totalUsers,isMultipleUsersDetected:(e?.totalUsers??0)>1,presenceSnippylyUserIds:e?.presenceSnippylyUserIds,presenceClientUserIds:e?.presenceClientUserIds})}catch(t){this.loggingService.catch("Error in LiveStateActionsService onAccessAccepted: ",t)}}onAccessRejected(e){try{this.triggerAction(Se.ACCESS_REJECTED,e),this.analyticsService.trackEvent(m.Events.LiveStateSync.SEM_ACCESS_REJECTED,{viewerUserId:e?.viewer?.userId,editorUserId:e?.editor?.userId,timestamp:e?.timestamp,status:e?.status,totalUsers:e?.totalUsers,isMultipleUsersDetected:(e?.totalUsers??0)>1,presenceSnippylyUserIds:e?.presenceSnippylyUserIds,presenceClientUserIds:e?.presenceClientUserIds})}catch(t){this.loggingService.catch("Error in LiveStateActionsService onAccessRejected: ",t)}}onEditorAssigned(e){try{this.triggerAction(Se.EDITOR_ASSIGNED,e),this.analyticsService.trackEvent(m.Events.LiveStateSync.SEM_EDITOR_ASSIGNED,{editorUserId:e?.editor?.userId,timestamp:e?.timestamp,role:e?.role,totalUsers:e?.totalUsers,isMultipleUsersDetected:(e?.totalUsers??0)>1,presenceSnippylyUserIds:e?.presenceSnippylyUserIds,presenceClientUserIds:e?.presenceClientUserIds})}catch(t){this.loggingService.catch("Error in LiveStateActionsService onEditorAssigned: ",t)}}onEditorOnDifferentTabDetected(e){try{this.triggerAction(Se.EDITOR_ON_DIFFERENT_TAB_DETECTED,e),this.analyticsService.trackEvent(m.Events.LiveStateSync.SEM_EDITOR_ON_DIFFERENT_TAB_DETECTED,{editorUserId:e?.editor?.userId,timestamp:e?.timestamp,role:e?.role,totalUsers:e?.totalUsers,isMultipleUsersDetected:(e?.totalUsers??0)>1,presenceSnippylyUserIds:e?.presenceSnippylyUserIds,presenceClientUserIds:e?.presenceClientUserIds})}catch(t){this.loggingService.catch("Error in LiveStateActionsService onEditorOnDifferentTabDetected: ",t)}}onViewerAssigned(e){try{this.triggerAction(Se.VIEWER_ASSIGNED,e),this.analyticsService.trackEvent(m.Events.LiveStateSync.SEM_VIEWER_ASSIGNED,{viewerUserId:e?.viewer?.userId,timestamp:e?.timestamp,role:e?.role,totalUsers:e?.totalUsers,isMultipleUsersDetected:(e?.totalUsers??0)>1,presenceSnippylyUserIds:e?.presenceSnippylyUserIds,presenceClientUserIds:e?.presenceClientUserIds})}catch(t){this.loggingService.catch("Error in LiveStateActionsService onViewerAssigned: ",t)}}triggerAction(e,t){try{this.actionSubjects.has(e)||this.actionSubjects.set(e,new ot),this.actionSubjects.get(e)?.next(t)}catch(i){this.loggingService.catch("Error in LiveStateActionsService triggerAction: ",i)}}onAction(e){try{return this.actionSubjects.has(e)||this.actionSubjects.set(e,new ot),this.actionSubjects.get(e)?.asObservable()}catch(t){return this.loggingService.catch("Error in LiveStateActionsService onAction: ",t),p(null)}}};r.\u0275fac=function(t){return new(t||r)(L(Xe),L(c))},r.\u0275prov=Ae({token:r,factory:r.\u0275fac,providedIn:"root"});let n=r;return n})();var Zt=(()=>{let r=class r{constructor(e,t,i,s,l){this.authService=e,this.coreActionsService=t,this.domService=i,this.loggingService=s,this.usersService=l}findOldestActiveSessionFromHeartbeats(e){try{if(!e||e.length===0)return null;let t=this.authService.getUser(),i=this.domService.getTabId(),s=e.filter(d=>d.lastUpdatedTimestamp>Date.now()-1e4);return s.length===0?null:[...s].sort((d,a)=>d.createdTimestamp-a.createdTimestamp)[0]??null}catch(t){return this.loggingService.catch("Error in findOldestActiveSessionFromHeartbeats: ",t),null}}determineEditorStatus(e){return Q(this,null,function*(){try{let{singleEditorModeData:t,heartbeatData:i,externalUserPresence:s,currentUser:l,currentTabId:u}=e,d=JSON.parse(JSON.stringify(t||{})),a={steps:[],timestamp:Date.now()},C=()=>Q(this,null,function*(){let ie=s?.userIds?.[0],se;if(ie){let ke=Qe(),Fe=xt.GET_SINGLE_EDITOR_USERS;this.coreActionsService.triggerAction(Je.USER_RESOLVER,{event:m.Events.Resolver.USER_RESOLUTION_REQUEST_FORMED,timestamp:new Date().getTime(),uniqueId:ke,moduleName:Fe,methodName:ze.SET_SINGLE_EDITOR_MODE_LIVE_STATE_DATA_FOR_DIFFERENT_USER_PRESENT_ON_TAB,source:"internal",payload:{userIds:[ie],forceResolve:!0}}),yield this.usersService.resolveUsers({userIds:[ie],forceResolve:!0,uniqueId:ke,moduleName:Fe}),se=this.usersService.getUserById(ie)}se?(d.editor=se,d.tabId=`differentUserPresentOnTab_${u}`):(d.editor={userId:`anonymous_${l?.userId}`,name:"Anonymous"},d.tabId=`differentUserPresentOnTab_${u}`)}),P=()=>{d.editor=l,d.tabId=`sameUserPresentOnTab_${u}`},O=!1;if(t?.editor){if(a.steps?.push("SingleEditorModeData: Editor is available."),i?.length){a.steps?.push("Heartbeat data is available.");let ie=i?.find(se=>se.userId===t?.editor?.userId&&se.tabId===t?.tabId);if(ie&&ie.lastUpdatedTimestamp>Date.now()-1e4)a.steps?.push("Editor user heartbeat is recent.");else{a.steps?.push("Editor user heartbeat is not available or not recent.");let se=this.findOldestActiveSessionFromHeartbeats(i);se&&se.userId===l.userId&&se.tabId===u?(a.steps?.push("Current user is the oldest active session."),O=!0):a.steps?.push("Current user is not the oldest active session.")}}!i?.length&&!s&&a.steps?.push("No heartbeat data and no external user presence is available.")}else{if(a.steps?.push("SingleEditorModeData: Editor not available."),i?.length){a.steps?.push("Heartbeat data is available.");let ie=this.findOldestActiveSessionFromHeartbeats(i);ie&&ie.userId===l.userId&&ie.tabId===u?(a.steps?.push("Current user is the oldest active session."),O=!0):a.steps?.push("Current user is not the oldest active session.")}else s&&(a.steps?.push("External user presence is available."),s.differentUserPresentOnTab?(a.steps?.push("External user presence: Different user is present on the tab."),yield C(),O=!1):s.sameUserPresentOnTab?(a.steps?.push("External user presence: Same user is present on the tab."),P(),O=!1):(a.steps?.push("External user presence: No user is present on the tab."),O=!0));!i?.length&&!s&&(a.steps?.push("No heartbeat data and no external user presence is available."),O=!0)}let w;return O?w={shouldSetUndefined:!0}:w={data:d},a.singleEditorModeData=t,a.singleEditorModeDataEditorAvailable=!!t?.editor,a.heartbeatData=i,a.externalUserPresence=s,a.currentUser=l,a.currentTabId=u,a.returnValue=w,a.shouldSetUndefined=O,a.steps?.push("Execution completed."),a=this.cleanStats(a),A(f({},w),{stats:a})}catch(t){return this.loggingService.catch("Error in determineEditorStatus: ",t),{data:e?.singleEditorModeData??void 0}}})}cleanStats(e){try{let t=e&&typeof e=="object"?JSON.parse(JSON.stringify(e)):e;return t?.singleEditorModeData?.editor&&(t.singleEditorModeData=A(f({},t.singleEditorModeData),{editor:{userId:t.singleEditorModeData?.editor?.userId}})),t?.returnValue?.data?.editor&&(t.returnValue.data=A(f({},t.returnValue.data),{editor:{userId:t.returnValue.data?.editor?.userId}})),t}catch{return e}}};r.\u0275fac=function(t){return new(t||r)(L(Oe),L(Ze),L(De),L(c),L(et))},r.\u0275prov=Ae({token:r,factory:r.\u0275fac,providedIn:"root"});let n=r;return n})();var T=(()=>{let r=class r{constructor(e,t,i,s,l,u,d,a,C,P,O,w,ie,se,ke,Fe,ui,vi){this.afAuth=e,this.analyticsService=t,this.authService=i,this.configService=s,this.coreActionsService=l,this.databaseService=u,this.docService=d,this.domService=a,this.heartbeatService=C,this.iamService=P,this.loggingService=O,this.commonDbService=w,this.liveStateActionsService=ie,this.liveStateUtilsService=se,this.usersService=ke,this.singleEditorDecisionEngine=Fe,this.serviceBook=ui,this.realtimeAdapter=vi,this.db=null,this.liveStateAutoSyncStateData$=new Y(null),this.liveStateDataMapDraft={},this.singleEditorMode$=new Y(!1),this.singleEditorModeConfig$=new Y(null),this.singleEditorLiveStateData$=new Y(null),this.singleEditorLiveStateData={},this.editorAccessTimeout$=new Y(ee.LIVE_STATE_REQUEST_EDITOR_ACCESS_WAIT_TIME),this.editorAccessTransferOnTimeOut$=new Y(!0),this.defaultSingleEditorUIEnabled$=new Y(!0),this.editorAccessTimer$=new Y(new Ke),this.autoSyncState$=new Y(!1),this.serverConnectionState$=new Y(K.PENDING_INIT),this.externalUserPresence$=new Y(null),this.heartbeat$=new Y(!0),this.user=null,this.keydownSubscription=null,this.isEditor$=new Y(null),this.preventEventsOnElementMap={},this.PREVENT_EVENTS=["click","mouseup","mousedown"],this.autoSyncStateHistory=null,this.singleEditorModeContainerIds$=new Y([]),this.inputChangeSubscriptionMap={},this.childListMutationSubscription=null,this.tabId=this.domService.getTabId(),this.heartbeatRestart$=new Y(void 0),this.connectionListenerUnsubscribe=null,this.offlineTimer=null;try{this.loggingService.log("%c[WB] Creating CLASS: LiveStateService","color: blue;"),pt([this.getSingleEditorMode$(),this.heartbeat$]).subscribe(([I,M])=>{I&&M?this.heartbeatService.enableHeartbeat():this.heartbeatService.disableHeartbeat()}),this.databaseService.getDb().pipe(k(I=>!!I),Te(1)).subscribe(I=>{I&&(this.db=I,this.getUser(),this.getDocumentPaths(),this.subscribeLiveStateData().subscribe(),this.subscribeAutoSyncState().subscribe(),this.singleEditorMode$.subscribe(M=>{M&&this.detectKeydownOnInput()}),this.autoSyncState$.subscribe(M=>{M?(this.detectLiveSyncInputs(),this.observeElementAddedOnDom()):(this.unsubscribeInputChanges(),this.childListMutationSubscription?.unsubscribe(),this.childListMutationSubscription=null)}),this.updateOnDatabaseDisconnect().subscribe(()=>{},M=>{this.loggingService.catch("Error in LiveStateService constructor updateOnDatabaseDisconnect: ",M)}),this.updateServerStateOnDatabaseDisconnect().subscribe(()=>{},M=>{this.loggingService.catch("Error in LiveStateService constructor updateServerStateOnDatabaseDisconnect: ",M)}))},I=>{this.loggingService.catch("Error in LiveStateService getDb subscription: ",I)}),this.liveStateAutoSyncStateData$.pipe(k(I=>Object.keys(I||{}).length>0),ne((I,M)=>JSON.stringify(I||{})===JSON.stringify(M||{}))).subscribe(I=>{I&&(this.getAutoSyncState()&&(!this.autoSyncStateHistory&&I?.history&&this.updateLiveStateSyncInputDataLocally(I.history),I?.current&&this.updateLiveStateSyncInputDataLocally({[I.current.liveStateDataId]:I.current})),!this.autoSyncStateHistory&&I?.history&&(this.autoSyncStateHistory=I.history))}),this.docService.addPreDocumentIdChangeFunction("live-state-service",I=>(this.updateExternalUserPresence(null),this.isUserEditor()?.isEditor&&(!this.getSingleEditorModeConfig()?.singleTabEditor||this.isUserEditor()?.isEditorOnCurrentTab)?this.removeEditorAccess({metadata:{from:"addPreDocumentIdChangeFunction-liveStateService",reason:"Document id changed"},documentPaths:I}):Promise.resolve())),this.authService.addPreSignOutFuction("live-state-signout",this.signOutUser.bind(this)),this.singleEditorLiveStateData$.pipe(Et()).subscribe(([I,M])=>{try{let ve=M?.requestEditorAccess?.status,be=I?.requestEditorAccess?.status,qe=this.authService.getUser(),$e=this.getPresenceData();if(ve==="pending"){if(qe?.userId===M?.editor?.userId){let _e=f({viewer:ae(M?.requestEditorAccess?.user)??void 0,editor:ae(M?.editor)??void 0,timestamp:new Date().getTime(),status:"requested"},$e);this.liveStateActionsService?.onAccessRequested(_e)}return}if(ve==="cancelled"){if(qe?.userId===M?.editor?.userId){let _e=f({viewer:ae(M?.requestEditorAccess?.user)??void 0,editor:ae(M?.editor)??void 0,timestamp:new Date().getTime(),status:"canceled"},$e);this.liveStateActionsService?.onAccessRequestCanceled(_e)}return}if(be==="pending"&&!ve){if(I?.requestEditorAccess?.user?.userId===M?.editor?.userId){if(I?.requestEditorAccess?.user?.userId===qe?.userId){let _e=f({viewer:ae(I?.editor)??void 0,editor:ae(M?.editor)??void 0,timestamp:new Date().getTime(),status:"accepted"},$e);this.liveStateActionsService?.onAccessAccepted(_e)}return}if(I?.requestEditorAccess?.user?.userId!==M?.editor?.userId){if(I?.requestEditorAccess?.user?.userId===qe?.userId){let _e=f({viewer:ae(I?.requestEditorAccess?.user)??void 0,editor:ae(M?.editor)??void 0,timestamp:new Date().getTime(),status:"rejected"},$e);this.liveStateActionsService?.onAccessRejected(_e)}return}}}catch(ve){this.loggingService.catch("Error in LiveStateService singleEditorLiveStateData$ subscription: ",ve)}}),this.isUserEditor$().pipe(ne(Ee)).subscribe(I=>{try{if(I){this.analyticsService.trackEvent(m.Events.LiveStateSync.SEM_USER_EDITOR_STATS,{isEditor:I?.isEditor,isEditorOnCurrentTab:I?.isEditorOnCurrentTab});let M=this.singleEditorLiveStateData$.value,ve=this.getPresenceData();if(I?.isEditor)if(I?.isEditorOnCurrentTab){let be=f({editor:ae(M?.editor)??void 0,timestamp:new Date().getTime(),role:"editor"},ve);this.liveStateActionsService?.onEditorAssigned(be)}else{let be=f({editor:ae(M?.editor)??void 0,timestamp:new Date().getTime(),role:"editorOnDifferentTab"},ve);this.liveStateActionsService?.onEditorOnDifferentTabDetected(be)}else{let be=f({viewer:ae(this.authService.getUser())??void 0,timestamp:new Date().getTime(),role:"viewer"},ve);this.liveStateActionsService?.onViewerAssigned(be)}}}catch(M){this.loggingService.catch("Error in LiveStateService isUserEditor$ subscription: ",M)}})}catch(I){this.loggingService.catch("Error in LiveStateService constructor: ",I)}}getPresenceData(){try{let t=this.serviceBook.get(wt)?.getPresenceUsers();return{totalUsers:t?.length,presenceSnippylyUserIds:t?.map(i=>i.userSnippylyId).filter(i=>!!i),presenceClientUserIds:t?.map(i=>i.userId)}}catch(e){return this.loggingService.catch("Error in LiveStateService getPresenceData: ",e),{}}}observeElementAddedOnDom(){try{this.loggingService.log("%c[WB] Calling FUNCTION: observeElementAddedOnDom","color: green;"),this.childListMutationSubscription&&(this.childListMutationSubscription.unsubscribe(),this.childListMutationSubscription=null),this.childListMutationSubscription=this.domService.getChildListMutation$().subscribe(e=>{e?.length&&e.forEach(t=>{let i=Array.from(t.addedNodes||[]).filter(s=>s instanceof HTMLElement);i?.forEach(s=>{Nt(s,!0)?.forEach(d=>{typeof d?.getAttribute=="function"&&d?.getAttribute(ee.ATTRIBUTES.VELT_SYNC_STATE)&&this.subscribeInputChanges(d)})}),i?.length&&this.isEditor$?.value?.isEditor===!1&&(this.disableInputElements(),this.disableElementEvents())})},e=>{this.loggingService.catch("Error in LiveStateService domService getChildListMutation$ subscription: ",e)})}catch(e){this.loggingService.catch("Error in LiveStateService observeElementAddedOnDom: ",e)}}detectKeydownOnInput(){try{this.loggingService.log("%c[WB] Calling FUNCTION: detectKeydownOnInput","color: green;"),this.unsubscribeKeydownSubscription(),this.keydownSubscription=this.domService.onWindowKeydown$().pipe(k(e=>e?.target instanceof HTMLInputElement||e?.target instanceof HTMLTextAreaElement||e?.target instanceof HTMLSelectElement),k(e=>!!this.isElementInsideSingleEditorModeContainerElements(e?.target)),Te(1)).subscribe(e=>{this.unsubscribeKeydownSubscription(),this.getSingleEditorModeConfig()?.customMode||this.setUserAsEditor({skipEditorCheck:!0})},e=>{this.loggingService.catch("Error in LiveStateService detectKeydownOnInput subscription: ",e)})}catch(e){this.loggingService.catch("Error in LiveStateService detectKeydownOnInput: ",e)}}unsubscribeKeydownSubscription(){try{this.loggingService.log("%c[WB] Calling FUNCTION: unsubscribeKeydownSubscription","color: green;"),this.keydownSubscription&&(this.keydownSubscription.unsubscribe(),this.keydownSubscription=null)}catch(e){this.loggingService.catch("Error in LiveStateService unsubscribeKeydownSubscription: ",e)}}getDocumentPaths(){try{this.loggingService.log("%c[WB] Calling FUNCTION: getDocumentPaths","color: green;"),this.docService.getDocumentPaths$().subscribe(e=>{this.documentPaths=e,this.updateLiveStateDataFromDraft()})}catch(e){this.loggingService.catch("Error in LiveStateService getDocumentPaths: ",e)}}getUser(){try{this.loggingService.log("%c[WB] Calling FUNCTION: getUser","color: green;"),this.authService.getUser$().subscribe(e=>{this.user=e,this.updateLiveStateDataFromDraft()})}catch(e){this.loggingService.catch("Error in LiveStateService getUser: ",e)}}updateLiveStateDataFromDraft(){try{this.loggingService.log("%c[WB] Calling FUNCTION: updateLiveStateDataFromDraft","color: green;"),this.liveStateDataMapDraft?.custom&&this.user&&this.documentPaths&&(Object.keys(this.liveStateDataMapDraft.custom).forEach(e=>{this.setLiveStateData(e,this.liveStateDataMapDraft.custom[e])}),this.liveStateDataMapDraft={})}catch(e){this.loggingService.catch("Error in LiveStateService updateLiveStateDataFromDraft: ",e)}}getActiveHeartbeatStream$(e){return this.heartbeatRestart$.pipe(Te(50),y(()=>{let t=this.heartbeatService.getHeartbeatData({documentId:this.documentPaths?.documentId}).pipe(Te(1),y(i=>{let s=this.singleEditorDecisionEngine.findOldestActiveSessionFromHeartbeats(i);return s?this.monitorSession$(s.userId,s.tabId):p(null)}));return!e?.userId||!e?.tabId?t:this.heartbeatService.getSpecificHeartbeat({userId:e.userId,tabId:e.tabId,documentId:this.documentPaths?.documentId}).pipe(Te(1),y(i=>!i?.id||Date.now()-i?.lastUpdatedTimestamp>1e4?t:this.monitorSession$(e.userId,e.tabId)))}),ne((t,i)=>this.isHeartbeatSimilar(t,i)))}monitorSession$(e,t){return this.heartbeatService.getSpecificHeartbeat({userId:e,tabId:t,documentId:this.documentPaths?.documentId}).pipe(y(s=>s?.id?p(s):(this.heartbeatRestart$.next(),st)),St({each:1e4,with:()=>(this.heartbeatRestart$.next(),st)}))}isHeartbeatSimilar(e,t){try{return!e&&!t?!0:!e||!t?!1:e?.userId===t?.userId&&e?.tabId===t?.tabId}catch{return!1}}subscribeLiveStateData(){return this.loggingService.log("%c[WB] Calling FUNCTION: getOnlineUsersOnCurrentDocument","color: green;"),this.authService.getAuthState$().pipe(k(e=>!!e),y(e=>this.isFeatureAllowed({firebaseUser:e,liveStateData:{}})),y(e=>e.featureAllowed?this.iamService.isUserAllowed$().pipe(D(t=>(e.featureAllowed=t,e))):p(e)),y(e=>e.featureAllowed?this.authService.isPlanExpired$().pipe(D(t=>(e.featureAllowed=!t,e))):p(e)),y(e=>e.featureAllowed?p(e).pipe(y(t=>this.docService.getDocumentPaths$().pipe(D(i=>(this.documentPaths=i,t.documentPaths=i,t)))),y(t=>t?.documentPaths?p(t).pipe(Ge(i=>{this.serverConnectionState$?.value===K.PENDING_INIT&&i?.documentPaths?.liveState&&this.serverConnectionState$.next(K.PENDING_DATA)}),y(i=>this.domService.onNetworkStatusChange$().pipe(k(s=>s),D(()=>i))),y(i=>this.getDataFromDocumentId().pipe(D(s=>(i.singleEditorModeData=s,f({},i))))),y(i=>this.getSingleEditorMode$().pipe(D(()=>i))),D(i=>([K.ONLINE,K.OFFLINE].includes(this.serverConnectionState$?.value)||this.serverConnectionState$.next(K.ONLINE),i)),y(i=>this.getSingleEditorMode()?this.getExternalUserPresence$().pipe(D(s=>A(f({},i),{externalUserPresence:s}))):p(i))):p(A(f({},t),{liveStateData:{}}))),y(t=>this.getSingleEditorMode()?this.heartbeatService.getHeartbeatEnabled$().pipe(y(i=>{if(i){let s=t?.singleEditorModeData?.editor,l=t?.singleEditorModeData?.tabId;return this.getActiveHeartbeatStream$({userId:s?.userId,tabId:l}).pipe(D(u=>{let d=u?.id?[u]:null;return A(f({},t),{heartbeatData:d})}))}else return p(A(f({},t),{heartbeatData:null}))})):p(t)),y(t=>{if(this.getSingleEditorMode()){let i=[];if(!(Object.keys(t?.singleEditorModeData||{}).length>0)){let l=this.singleEditorLiveStateData$.value&&typeof this.singleEditorLiveStateData$.value=="object"?JSON.parse(JSON.stringify(this.singleEditorLiveStateData$.value)):this.singleEditorLiveStateData$.value;i.push({eventName:m.Events.LiveStateSync.SEM_SINGLE_EDITOR_LIVE_STATE_EMPTY_DATA_STATS,properties:{previousSingleEditorModeData:l,currentSingleEditorModeData:t?.singleEditorModeData}})}return this.updateSingleEditorLiveSyncData(t?.singleEditorModeData||{},t?.externalUserPresence??null,t?.heartbeatData??null,t,i),p(t)}else return p(t)})):p({})))}updateSingleEditorLiveSyncData(e,t,i,s,l){return Q(this,null,function*(){try{this.loggingService.log("%c[WB] Calling FUNCTION: updateSingleEditorLiveSyncData","color: green;"),pe(e,{})&&!this.keydownSubscription&&this.detectKeydownOnInput();let u=JSON.parse(JSON.stringify(e)),d=yield this.singleEditorDecisionEngine.determineEditorStatus({singleEditorModeData:u,externalUserPresence:t,heartbeatData:i,currentUser:this.authService.getUser(),currentTabId:this.tabId});d?.stats&&l?.push({eventName:m.Events.LiveStateSync.SEM_SINGLE_EDITOR_DETERMINE_EDITOR_STATUS,properties:{stats:d?.stats}});let a;if(this.domService.getNetworkStatus()||(a=null),e=d?.data??{},d?.shouldSetUndefined||(a=null),(s?s?.documentPaths:this.docService.getDocumentPaths())||(a=null),e&&!e?.editor&&this.isEditor$?.value!==a&&this.isEditor$.next(a),pe(this.singleEditorLiveStateData,e))return;{t&&this.compareServerAndExternalData(u,t),l&&l?.length>0&&l.forEach(O=>{O?.eventName&&this.analyticsService.trackEvent(O.eventName,O.properties)}),this.singleEditorLiveStateData=e,this.singleEditorLiveStateData$.next(e);let P;if(this.singleEditorLiveStateData&&typeof this.singleEditorLiveStateData=="object"&&(P=this.liveStateUtilsService.formatLiveStateSingleEditorModeData(JSON.parse(JSON.stringify(this.singleEditorLiveStateData)))),this.analyticsService.trackEvent(m.Events.LiveStateSync.SEM_SINGLE_EDITOR_LIVE_STATE_DATA_STATS,{singleEditorLiveStateData:P}),this.singleEditorLiveStateData?.editor){let O=this.authService.getUser();this.singleEditorLiveStateData?.editor?.userId!==O?.userId?this.makeReader():this.makeEditor()}else this.isEditor$?.value!==a&&this.isEditor$.next(a),this.enableInputElements(),this.enableElementEvents();this.editorAccessTimerInterval&&this.singleEditorLiveStateData?.requestEditorAccess?.status!=="pending"&&this.clearEditorAccessTimerInterval(),this.requestAccessTimer&&this.singleEditorLiveStateData?.requestEditorAccess?.status!=="pending"?this.clearRequestAccessTimer():this.singleEditorLiveStateData?.requestEditorAccess?.status==="pending"&&this.isUserEditor()?.isEditor&&this.isUserEditor()?.isEditorOnCurrentTab&&this.setRequestAccessTimer(this.singleEditorLiveStateData?.requestEditorAccess?.editorAccessTimeout||ee.LIVE_STATE_REQUEST_EDITOR_ACCESS_WAIT_TIME)}}catch{}})}updateSingleEditorLiveSyncDataOld(s,l){return Q(this,arguments,function*(e,t,i=[]){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: updateSingleEditorLiveSyncData","color: green;"),pe(e,{})){let a=yield this.fetchSingleEditorLiveStateDataFromDatabase();if(!pe(a,e)&&(i.push({eventName:m.Events.LiveStateSync.SEM_SINGLE_EDITOR_LIVE_STATE_DATA_MISMATCH,properties:{serverData:a,localData:e}}),a&&typeof a=="object")){let C=yield this.liveStateUtilsService.resolveAndMergeSingleEditorLiveStateDataWithUser(JSON.parse(JSON.stringify(a)));e=JSON.parse(JSON.stringify(C))}}pe(e,{})&&!this.keydownSubscription&&this.detectKeydownOnInput();let u=e&&typeof e=="object"?JSON.parse(JSON.stringify(e)):e;if(t&&(e&&typeof e=="object"&&(e=JSON.parse(JSON.stringify(e))),!e?.editor)){let a=this.authService.getUser();if(t?.sameUserPresentOnTab)e.editor=a,e.tabId=`sameUserPresentOnTab_${this.tabId}`;else if(t?.differentUserPresentOnTab){let C=t?.userIds?.[0],P;if(C){let O=Qe();this.coreActionsService.triggerAction(Je.USER_RESOLVER,{event:m.Events.Resolver.USER_RESOLUTION_REQUEST_FORMED,timestamp:new Date().getTime(),uniqueId:O,methodName:ze.GET_SINGLE_EDITOR_MODE_DATA,source:"internal",payload:{userIds:[C],forceResolve:!0}}),yield this.usersService.resolveUsers({userIds:[C],forceResolve:!0,uniqueId:O}),P=this.usersService.getUserById(C)}P?(e.editor=P,e.tabId=`differentUserPresentOnTab_${this.tabId}`):(e.editor={userId:`anonymous_${a?.userId}`,name:"Anonymous"},e.tabId=`differentUserPresentOnTab_${this.tabId}`)}}let d;if(this.domService.getNetworkStatus()||(d=null),e&&!e?.editor&&this.isEditor$?.value!==d&&!t?.sameUserPresentOnTab&&!t?.differentUserPresentOnTab&&this.isEditor$.next(d),pe(this.singleEditorLiveStateData,e))return;{t&&this.compareServerAndExternalData(u,t),i?.length>0&&i.forEach(C=>{C?.eventName&&this.analyticsService.trackEvent(C.eventName,C.properties)}),this.singleEditorLiveStateData=e,this.singleEditorLiveStateData$.next(e);let a;if(this.singleEditorLiveStateData&&typeof this.singleEditorLiveStateData=="object"&&(a=this.liveStateUtilsService.formatLiveStateSingleEditorModeData(JSON.parse(JSON.stringify(this.singleEditorLiveStateData)))),this.analyticsService.trackEvent(m.Events.LiveStateSync.SEM_SINGLE_EDITOR_LIVE_STATE_DATA_STATS,{singleEditorLiveStateData:a}),this.singleEditorLiveStateData?.editor){let C=this.authService.getUser();this.singleEditorLiveStateData?.editor?.userId!==C?.userId?this.makeReader():this.makeEditor()}else this.isEditor$?.value!==d&&this.isEditor$.next(d),this.enableInputElements(),this.enableElementEvents();this.editorAccessTimerInterval&&this.singleEditorLiveStateData?.requestEditorAccess?.status!=="pending"&&this.clearEditorAccessTimerInterval(),this.requestAccessTimer&&this.singleEditorLiveStateData?.requestEditorAccess?.status!=="pending"?this.clearRequestAccessTimer():this.singleEditorLiveStateData?.requestEditorAccess?.status==="pending"&&this.isUserEditor()?.isEditor&&this.isUserEditor()?.isEditorOnCurrentTab&&this.setRequestAccessTimer(this.singleEditorLiveStateData?.requestEditorAccess?.editorAccessTimeout||ee.LIVE_STATE_REQUEST_EDITOR_ACCESS_WAIT_TIME)}}catch{}})}compareServerAndExternalData(e,t){try{if(t){let i=this.authService.getUser(),s={isEditor:e?.editor?.userId===i?.userId,isEditorOnCurrentTab:e?.editor?.userId===i?.userId&&e?.tabId===this.tabId},l={isEditor:t?.sameUserPresentOnTab&&!t?.differentUserPresentOnTab,isEditorOnCurrentTab:!1};pe(s,l)||this.analyticsService.trackEvent(m.Events.LiveStateSync.SEM_SINGLE_EDITOR_DATA_MISMATCH_WITH_EXTERNAL,{serverUserEditorAccess:s,externalUserEditorAccess:l,serverData:e,externalData:t})}}catch(i){this.loggingService.catch("Error in LiveStateService compareServerAndExternalData: ",i)}}isFeatureAllowed(e){return this.configService.getConfig$().pipe(k(t=>!!t),D(t=>A(f({},e),{config:t})),y(t=>this.authService.getUser$().pipe(D(i=>A(f({},t),{user:i})))),y(t=>lt(t.config,t.user,ct.LIVE_STATE_SYNC)?p(A(f({},t),{featureAllowed:!0})):(this.loggingService.warn("Live state sync feature is not allowed."),p(A(f({},t),{featureAllowed:!1})))),ne((t,i)=>t?.featureAllowed===i?.featureAllowed))}getDataFromDocumentId(e){return this.databaseService.getDb().pipe(k(t=>!!t),y(t=>(this.db=t,this.configService?.getApiKey()&&this.documentPaths?.liveState?this.commonDbService.dbListener({feature:"liveStateSingleEditorMode",properties:{documentId:e??this.documentPaths?.documentId,organizationId:this.documentPaths?.organizationId,skipFirestore:!0}}).pipe(k(i=>!!i?.data),D(i=>i?.data&&typeof i?.data=="object"?JSON.parse(JSON.stringify(i?.data)):i?.data),Be(i=>(this.loggingService.catch("Error in LiveStateService getDataFromDocumentId: ",i),p({})))):p({}))),ne(Ee))}getLiveStateData$(e,t){try{return this.loggingService.log("%c[WB] Calling FUNCTION: getLiveStateData$","color: green;"),this.authService.getAuthState$().pipe(k(i=>!!i),y(i=>this.isFeatureAllowed({firebaseUser:i,liveStateData:{}})),y(i=>i.featureAllowed?this.iamService.isUserAllowed$().pipe(D(s=>(i.featureAllowed=s,i))):p(i)),y(i=>i.featureAllowed?this.authService.isPlanExpired$().pipe(D(s=>(i.featureAllowed=!s,i))):p(i)),y(i=>i.featureAllowed?p(i).pipe(y(s=>this.docService.getDocumentPaths$().pipe(D(l=>(this.documentPaths=l,s.documentPaths=l,s)))),y(s=>{let l=t?.listenToNewChangesOnly?1:0;return this.getLiveStateDataFromDatabase$(e).pipe(ne(Ee),ft(l))}),D(s=>{if(s)if(e){let l=Ie(e+""),u=s?.[l];if(u){let d=u?.data;if(u?.tabId&&this.tabId&&u?.tabId===this.tabId)return;if(u?.isDataStringified&&typeof d=="string")try{d=JSON.parse(d)}catch{}return d}else return}else{let l={};return Object.keys(s||{}).forEach(u=>{if(s[u]?.liveStateDataId){let d=s[u],a=d?.data;if(d?.isDataStringified&&typeof a=="string")try{a=JSON.parse(a)}catch{}l[d.liveStateDataId]=a}}),l}return s})):p(void 0).pipe(k(Boolean))),ne((i,s)=>JSON.stringify(i||{})===JSON.stringify(s||{})),k(i=>i!==void 0),D(i=>i))}catch(i){return this.loggingService.catch("Error in LiveStateService getLiveStateData$: ",i),p(null)}}getLiveStateDataFromDatabase$(e){try{return this.databaseService.getDb().pipe(k(t=>!!t),y(t=>{this.db=t;let i=e?Ie(e+""):void 0;return this.configService?.getApiKey()&&this.documentPaths?.liveState?this.commonDbService.dbListener({feature:i?"liveStateCustom":"allLiveStateCustoms",properties:{documentId:this.documentPaths?.documentId,organizationId:this.documentPaths?.organizationId,id:i,skipFirestore:!0}}).pipe(k(s=>!!s?.data),D(s=>s?.data),D(s=>{if(s)return i?{[i]:s}:s}),Be(s=>(this.loggingService.catch("Error in LiveStateService getLiveStateDataFromDatabase$: ",s),p(null)))):p(void 0)}))}catch(t){return this.loggingService.catch("Error in LiveStateService getLiveStateDataFromDatabase$: ",t),p(void 0)}}fetchLiveStateData(e){return Q(this,null,function*(){try{this.loggingService.log("%c[WB] Calling FUNCTION: fetchLiveStateData","color: green;");let t=this.databaseService.getDbValue(),i=this.authService.getUser(),s=this.docService.getDocumentPaths(),l=e?.liveStateDataId&&typeof e?.liveStateDataId=="string"?Ie(e.liveStateDataId):void 0,u=lt(this.configService.getConfig(),i,ct.LIVE_STATE_SYNC);if(this.authService.isPlanExpired()&&(u=!1),t&&i&&s?.liveState&&u){let a=yield this.commonDbService.getData({feature:l?"liveStateCustom":"allLiveStateCustoms",properties:{documentId:s?.documentId,organizationId:s?.organizationId,id:l,skipFirestore:!0}}).then(C=>C?l?{[l]:C}:C:null);if(a)if(l){let C=a?.[l];if(C){let P=C?.data;if(C?.isDataStringified&&typeof P=="string")try{P=JSON.parse(P)}catch{}return P}else return null}else{let C={};return Object.keys(a||{}).forEach(P=>{if(a[P]?.liveStateDataId){let O=a[P],w=O?.data;if(O?.isDataStringified&&typeof w=="string")try{w=JSON.parse(w)}catch{}C[O.liveStateDataId]=w}}),C}}return null}catch(t){return this.loggingService.catch("Error in LiveStateService fetchLiveStateData: ",t),null}})}setLiveStateData(e,t,i){return Q(this,null,function*(){this.loggingService.log("%c[WB] Calling FUNCTION: setLiveStateData","color: green;");try{let s=this.authService.getUser();if(e&&this.documentPaths?.liveState&&s){let l=Ie(e+""),u=!1;try{if(i?.merge&&typeof t=="object"){let a=yield this.commonDbService.getData({feature:"liveStateCustom",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",id:l,skipFirestore:!0}});if(a?.isDataStringified){let C=JSON.parse(a?.data);typeof t=="object"&&(t=f(f({},C),t))}}}catch{}try{typeof t=="object"&&(t=JSON.stringify(t),u=!0)}catch{}let d={id:l,lastUpdated:this.timestamp,liveStateDataId:e,data:t,updatedBy:s,tabId:this.tabId,isDataStringified:u};yield this.commonDbService.setData({feature:"liveStateCustom",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",id:l,skipFirestore:!0},data:JSON.parse(JSON.stringify(d))})}else this.loggingService.warn("liveStateDataId or documentPaths or user is null"),this.liveStateDataMapDraft?.custom||(this.liveStateDataMapDraft.custom={}),e&&(this.liveStateDataMapDraft.custom[e]=t)}catch(s){this.loggingService.catch("Error in LiveStateService _setLiveStateData: ",s)}})}getFormElements(){try{return this.loggingService.log("%c[WB] Calling FUNCTION: getInputElements","color: green;"),document.querySelectorAll("input, textarea, select, button, [contenteditable]")}catch(e){return this.loggingService.catch("Error in LiveStateService getInputElements: ",e),null}}disableInputElements(){try{this.loggingService.log("%c[WB] Calling FUNCTION: disableInputElements","color: green;"),this.getFormElements()?.forEach(t=>{if(this.isElementInsideSingleEditorModeContainerElements(t)&&!this.isSingleEditorModeDisabledForElement(t)&&!Rt(t)){let i=t?.hasAttribute("disabled");t?.hasAttribute("contenteditable")&&(i=t?.getAttribute("contenteditable")==="false"),i||(t.setAttribute("disabled","true"),t.setAttribute(ee.ATTRIBUTES.VELT_SYNC_ACCESS_AUTO,"true"),t?.hasAttribute("contenteditable")&&t.setAttribute("contenteditable","false"))}})}catch(e){this.loggingService.catch("Error in LiveStateService disableInputElements: ",e)}}enableInputElements(){try{this.loggingService.log("%c[WB] Calling FUNCTION: enableInputElements","color: green;"),this.getFormElements()?.forEach(t=>{t?.hasAttribute(ee.ATTRIBUTES.VELT_SYNC_ACCESS_AUTO)&&(t.removeAttribute("disabled"),t.removeAttribute(ee.ATTRIBUTES.VELT_SYNC_ACCESS_AUTO),t?.getAttribute("contenteditable")&&t.setAttribute("contenteditable","true"))})}catch(e){this.loggingService.catch("Error in LiveStateService enableInputElements: ",e)}}disableElementEvents(){try{this.loggingService.log("%c[WB] Calling FUNCTION: disableElementEvents","color: green;"),document.querySelectorAll(`[${ee.ATTRIBUTES.VELT_SYNC_ACCESS}]`)?.forEach(t=>{let i=this.domService.getXPath(t);i&&!this.preventEventsOnElementMap[i]&&(this.preventEventsOnElementMap[i]={element:t,events:{}},this.PREVENT_EVENTS.forEach(s=>{let l=Le(t,s,{capture:!0}).subscribe(u=>{try{u.preventDefault(),u.stopPropagation()}catch(d){this.loggingService.catch("Error in LiveStateService disableElementEvents subscription: ",d)}});this.preventEventsOnElementMap[i]?.events[s]?.unsubscribe(),this.preventEventsOnElementMap[i].events[s]=l}))})}catch(e){this.loggingService.catch("Error in LiveStateService disableElementClicks: ",e)}}enableElementEvents(){try{this.loggingService.log("%c[WB] Calling FUNCTION: enableElementEvents","color: green;"),Object.keys(this.preventEventsOnElementMap).forEach(e=>{let t=this.preventEventsOnElementMap[e];Object.keys(t.events||{}).forEach(i=>{t?.events[i]?.unsubscribe()})}),this.preventEventsOnElementMap={}}catch(e){this.loggingService.catch("Error in LiveStateService enableElementClicks: ",e)}}setUserAsEditor(e){return Q(this,null,function*(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: setUserAsEditor","color: green;"),this.user&&this.documentPaths?.liveStateSingleEditorMode){if(this.analyticsService.trackEvent(m.Events.LiveStateSync.SET_USER_AS_EDITOR_TRIGGERED,{editorUserId:this.user?.userSnippylyId,tabId:this.tabId}),!e?.skipEditorCheck){let i=yield this.fetchSingleEditorLiveStateDataFromDatabase();if(i?.editor?.userId&&i?.tabId){let s=yield ht(this.heartbeatService.getSpecificHeartbeat({userId:i?.editor?.userId,tabId:i?.tabId,documentId:this.documentPaths?.documentId})),l=null;s&&(l=this.singleEditorDecisionEngine.findOldestActiveSessionFromHeartbeats([s])),l||(i=null)}else i=null;if(i?.editor){let s=this.authService.getUser(),l=null;s?.userId===i?.editor?.userId?i?.tabId===this.tabId?l={code:"same_user_editor_current_tab",message:"Same user is already editor in current tab.",source:"setUserAsEditor"}:l={code:"same_user_editor_different_tab",message:"Same user is already editor in different tab.",source:"setUserAsEditor"}:l={code:"another_user_editor",message:"Another user is already editor.",source:"setUserAsEditor"};let u;return i&&typeof i=="object"&&(u=this.liveStateUtilsService.formatLiveStateSingleEditorModeData(JSON.parse(JSON.stringify(i)))),this.analyticsService.trackEvent(m.Events.LiveStateSync.SET_USER_AS_EDITOR_ERROR,{error:l,singleEditorLiveStateData:u}),{error:l}}}let t={editor:this.user,tabId:this.tabId,editorAt:this.timestamp};this.commonDbService.setData({feature:"liveStateSingleEditorMode",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0,rtdbTransaction:!0},data:JSON.parse(JSON.stringify(t))})}}catch(t){this.loggingService.catch("Error in LiveStateService setUserAsEditor: ",t)}})}fetchSingleEditorLiveStateDataFromDatabase(){return Q(this,null,function*(){try{return this.loggingService.log("%c[WB] Calling FUNCTION: fetchSingleEditorLiveStateDataFromDatabase","color: green;"),yield this.commonDbService.getData({feature:"liveStateSingleEditorMode",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0}})}catch(e){return this.loggingService.catch("Error in LiveStateService fetchSingleEditorLiveStateDataFromDatabase: ",e),null}})}setRequestAccessTimer(e){try{this.loggingService.log("%c[WB] Calling FUNCTION: setRequestAccessTimer","color: green;"),this.requestAccessTimer||(this.requestAccessTimer=setTimeout(()=>{this.getEditorAccessTransferOnTimeOut()&&this.acceptEditorAccessRequest(),this.clearRequestAccessTimer()},e*1e3),this.setEditorAccessTimerInterval(e))}catch(t){this.loggingService.catch("Error in LiveStateService setRequestAccessTimer: ",t)}}clearRequestAccessTimer(){try{this.loggingService.log("%c[WB] Calling FUNCTION: clearRequestAccessTimer","color: green;"),this.requestAccessTimer&&(clearTimeout(this.requestAccessTimer),this.requestAccessTimer=null)}catch(e){this.loggingService.catch("Error in LiveStateService clearRequestAccessTimer: ",e)}}requestEditorAccess(){this.loggingService.log("%c[WB] Calling FUNCTION: requestEditorAccess","color: green;");try{return this.serverConnectionState$.value===K.OFFLINE?(this.loggingService.catch("User is offline."),p(null)):(this.analyticsService.trackEvent(m.Events.LiveStateSync.REQUEST_EDITOR_ACCESS_TRIGGERED),new mt(e=>{let t=null;try{if(this.user&&this.documentPaths?.liveStateSingleEditorMode){let i=this.getEditorAccessTimeout(),s=this.realtimeAdapter.rtdbRef(this.db,`${this.documentPaths?.liveStateSingleEditorMode}`),l={requestEditorAccess:{user:this.user,requestedAt:this.timestamp,status:"pending",editorAccessTimeout:i,tabId:this.tabId}};this.commonDbService.updateData({feature:"liveStateSingleEditorMode",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0,rtdbTransaction:!0},errorCallback:u=>{this.loggingService.catch("Error in LiveStateService requestEditorAccess: ",u),e.next(null),e.complete()},callback:()=>{i&&(this.requestAccessTimer=setTimeout(()=>{this.getEditorAccessTransferOnTimeOut()&&this.setUserAsEditor({skipEditorCheck:!0})},(i+3)*1e3),this.setEditorAccessTimerInterval(i+3)),t=this.getSingleEditorLiveStateData$().subscribe(u=>{u&&(u?.requestEditorAccess?u?.requestEditorAccess?.status==="cancelled"&&(e.next(null),e.complete()):u?.editor?.userId===this.user?.userId?(e.next(!0),e.complete()):(e.next(!1),e.complete()))})},data:JSON.parse(JSON.stringify(l))})}else e.next(!1),e.complete()}catch(i){this.loggingService.catch("Error in LiveStateService requestEditorAccess: ",i),e.next(null),e.complete()}return()=>{t&&t?.unsubscribe()}}))}catch(e){return this.loggingService.catch("Error in LiveStateService requestEditorAccess: ",e),p(null)}}makeEditor(){try{this.loggingService.log("%c[WB] Calling FUNCTION: makeEditor","color: green;");let e=this.singleEditorLiveStateData?.tabId===this.tabId;this.analyticsService.trackEvent(m.Events.LiveStateSync.SEM_MAKE_EDITOR_TRIGGERED,{editorUserId:this.singleEditorLiveStateData?.editor?.userId,tabId:this.tabId,editorTabId:this.singleEditorLiveStateData?.tabId,isEditor:!0,isEditorOnCurrentTab:e}),this.isEditor$.next({isEditor:!0,isEditorOnCurrentTab:e}),this.getSingleEditorModeConfig()?.customMode||(!this.getSingleEditorModeConfig()?.singleTabEditor||e?(this.enableInputElements(),this.enableElementEvents()):(this.disableInputElements(),this.disableElementEvents())),this.fetchSingleEditorLiveStateDataFromDatabase().then(t=>{this.analyticsService.trackEvent(m.Events.LiveStateSync.SEM_SINGLE_EDITOR_LIVE_STATE_DATA_ON_MAKE_EDITOR,{editorUserId:this.singleEditorLiveStateData?.editor?.userId,tabId:this.tabId,editorTabId:this.singleEditorLiveStateData?.tabId,isEditor:!0,isEditorOnCurrentTab:e,singleEditorLiveStateDataOnServer:t})}).catch(t=>{})}catch(e){this.loggingService.catch("Error in LiveStateService makeEditor: ",e)}}makeReader(){try{this.loggingService.log("%c[WB] Calling FUNCTION: makeReader","color: green;"),this.analyticsService.trackEvent(m.Events.LiveStateSync.SEM_MAKE_READER_TRIGGERED,{editorUserId:this.singleEditorLiveStateData?.editor?.userId,tabId:this.tabId,editorTabId:this.singleEditorLiveStateData?.tabId,isEditor:!1,isEditorOnCurrentTab:!1}),this.isEditor$.next({isEditor:!1,isEditorOnCurrentTab:!1}),this.getSingleEditorModeConfig()?.customMode||(this.disableInputElements(),this.disableElementEvents()),this.fetchSingleEditorLiveStateDataFromDatabase().then(e=>{this.analyticsService.trackEvent(m.Events.LiveStateSync.SEM_SINGLE_EDITOR_LIVE_STATE_DATA_ON_MAKE_READER,{editorUserId:this.singleEditorLiveStateData?.editor?.userId,tabId:this.tabId,editorTabId:this.singleEditorLiveStateData?.tabId,isEditor:!1,isEditorOnCurrentTab:!1,singleEditorLiveStateDataOnServer:e})}).catch(e=>{})}catch(e){this.loggingService.catch("Error in makeReader: ",e)}}acceptEditorAccessRequest(){return Q(this,null,function*(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: acceptEditorAccessRequest","color: green;"),this.serverConnectionState$.value===K.OFFLINE){this.loggingService.catch("User is offline.");return}if(this.user&&this.singleEditorLiveStateData?.requestEditorAccess&&this.isUserEditor()?.isEditor&&this.documentPaths?.liveStateSingleEditorMode){let e=this.singleEditorLiveStateData?.requestEditorAccess?.user,t=this.singleEditorLiveStateData?.requestEditorAccess?.tabId;if(e&&t){let i={editor:e,requestEditorAccess:null,tabId:t,editorAt:this.timestamp};this.commonDbService.updateData({feature:"liveStateSingleEditorMode",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0,rtdbTransaction:!0},data:JSON.parse(JSON.stringify(i))}),this.analyticsService.trackEvent(m.Events.LiveStateSync.ACCEPT_EDITOR_ACCESS_REQUEST_TRIGGERED,{editorUserId:e?.userSnippylyId,tabId:t})}}}catch(e){this.loggingService.catch("Error in acceptEditorAccessRequest: ",e)}})}rejectEditorAccessRequest(){return Q(this,null,function*(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: rejectEditorAccessRequest","color: green;"),this.serverConnectionState$.value===K.OFFLINE){this.loggingService.catch("User is offline.");return}if(this.user&&this.singleEditorLiveStateData?.requestEditorAccess&&this.isUserEditor()?.isEditor&&this.documentPaths?.liveStateSingleEditorMode){let e={requestEditorAccess:null};this.commonDbService.updateData({feature:"liveStateSingleEditorMode",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0,rtdbTransaction:!0},data:JSON.parse(JSON.stringify(e))}),this.analyticsService.trackEvent(m.Events.LiveStateSync.REJECT_EDITOR_ACCESS_REQUEST_TRIGGERED)}}catch(e){this.loggingService.catch("Error in LiveStateService rejectEditorAccessRequest: ",e)}})}cancelEditorAccessRequest(){return Q(this,null,function*(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: cancelEditorAccessRequest","color: green;"),this.serverConnectionState$.value===K.OFFLINE){this.loggingService.catch("User is offline.");return}if(this.user&&this.singleEditorLiveStateData?.requestEditorAccess&&this.documentPaths?.liveStateSingleEditorMode){let e={requestEditorAccess:A(f({},this.singleEditorLiveStateData?.requestEditorAccess),{status:"cancelled"})};this.commonDbService.updateData({feature:"liveStateSingleEditorMode",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0,rtdbTransaction:!0},data:JSON.parse(JSON.stringify(e))}),e={requestEditorAccess:null},this.commonDbService.updateData({feature:"liveStateSingleEditorMode",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0,rtdbTransaction:!0},data:JSON.parse(JSON.stringify(e))}),this.analyticsService.trackEvent(m.Events.LiveStateSync.CANCEL_EDITOR_ACCESS_REQUEST_TRIGGERED)}}catch(e){this.loggingService.catch("Error in LiveStateService cancelEditorAccessRequest: ",e)}})}editCurrentTab(){return Q(this,null,function*(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: editCurrentTab","color: green;"),this.serverConnectionState$.value===K.OFFLINE){this.loggingService.catch("User is offline.");return}if(this.user&&this.isUserEditor()?.isEditor&&!this.isUserEditor()?.isEditorOnCurrentTab&&this.documentPaths?.liveStateSingleEditorMode){let e={tabId:this.tabId,editor:this.user,editorAt:this.timestamp};this.commonDbService.updateData({feature:"liveStateSingleEditorMode",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0,rtdbTransaction:!0},data:JSON.parse(JSON.stringify(e))}),this.analyticsService.trackEvent(m.Events.LiveStateSync.EDIT_CURRENT_TAB_TRIGGERED,{tabId:this.tabId})}}catch(e){this.loggingService.catch("Error in LiveStateService editCurrentTab: ",e)}})}isUserEditor$(){try{return this.loggingService.log("%c[WB] Calling FUNCTION: isUserEditor$","color: green;"),this.isEditor$.asObservable().pipe(ne(Ee))}catch(e){return this.loggingService.catch("Error in LiveStateService isUserEditor$: ",e),p(null)}}isUserEditor(){try{return this.loggingService.log("%c[WB] Calling FUNCTION: isUserEditor","color: green;"),this.isEditor$.value}catch(e){return this.loggingService.catch("Error in LiveStateService isUserEditor: ",e),null}}getEditor$(){try{return this.loggingService.log("%c[WB] Calling FUNCTION: getEditor$","color: green;"),this.getSingleEditorLiveStateData$().pipe(D(e=>e?.editor||null),ne())}catch(e){return this.loggingService.catch("Error in LiveStateService getEditor$: ",e),p(null)}}isEditorAccessRequested$(){try{return this.loggingService.log("%c[WB] Calling FUNCTION: isEditorAccessRequested$","color: green;"),this.isUserEditor$().pipe(y(e=>e?.isEditor?this.singleEditorLiveStateData$.pipe(D(t=>t?.requestEditorAccess?{requestStatus:"requested",requestedBy:t?.requestEditorAccess?.user}:null)):p(null)),ne((e,t)=>JSON.stringify(e||{})===JSON.stringify(t||{})))}catch(e){return this.loggingService.catch("Error in LiveStateService isEditorAccessRequested$: ",e),p(null)}}removeEditorAccess(e){return Q(this,null,function*(){try{this.loggingService.log("%c[WB] Calling FUNCTION: removeEditorAccess","color: green;"),this.analyticsService.trackEvent(m.Events.LiveStateSync.REMOVE_EDITOR_ACCESS,{removeEditorAccessMetadata:e?.metadata});let t=e?.documentPaths??this.documentPaths;(this.user||this.authService.getAuthUser())&&t?.liveStateSingleEditorMode&&(yield this.commonDbService.deleteData({feature:"liveStateSingleEditorMode",properties:{documentId:t?.documentId??"",organizationId:t?.organizationId??"",skipFirestore:!0}}))}catch(t){this.loggingService.catch("Error in LiveStateService removeEditorAccess: ",t)}})}getSingleEditorLiveStateData$(){return this.singleEditorLiveStateData$.asObservable().pipe(ne(Ee))}subscribeAutoSyncState(){return this.loggingService.log("%c[WB] Calling FUNCTION: getOnlineUsersOnCurrentDocument","color: green;"),this.authService.getAuthState$().pipe(k(e=>!!e),y(e=>this.isFeatureAllowed({firebaseUser:e,liveStateData:{}})),y(e=>e.featureAllowed?this.iamService.isUserAllowed$().pipe(D(t=>(e.featureAllowed=t,e))):p(e)),y(e=>e.featureAllowed?this.authService.isPlanExpired$().pipe(D(t=>(e.featureAllowed=!t,e))):p(e)),y(e=>e.featureAllowed?p(e).pipe(y(t=>this.docService.getDocumentPaths$().pipe(k(i=>!!i),D(i=>(this.documentPaths=i,t.documentPaths=i,t)))),y(t=>this.domService.onNetworkStatusChange$().pipe(k(i=>i),D(()=>t))),y(t=>this.getLiveStateAutoSyncStateDataFromDocumentId().pipe(D(i=>(t.liveStateData=i,f({},t))))),D(t=>{if(t.liveStateData)this.liveStateAutoSyncStateData$.next(t.liveStateData);else{let i=this.liveStateAutoSyncStateData$.value;i&&Object.keys(i).length>0&&this.liveStateAutoSyncStateData$.next({})}return t})):p({})))}getLiveStateAutoSyncStateDataFromDocumentId(e){return this.databaseService.getDb().pipe(k(t=>!!t),y(t=>(this.db=t,this.configService?.getApiKey()&&this.documentPaths?.liveState?this.commonDbService.dbListener({feature:"liveStateAutoSyncState",properties:{documentId:e??this.documentPaths?.documentId,organizationId:this.documentPaths?.organizationId,skipFirestore:!0}}).pipe(k(i=>!!i?.data),D(i=>i?.data&&typeof i?.data=="object"?JSON.parse(JSON.stringify(i?.data)):i?.data),Be(i=>(this.loggingService.catch("Error in LiveStateService getLiveStateAutoSyncStateDataFromDocumentId: ",i),p({})))):p({}))),ne(Ee))}enableSingleEditorMode(e){try{if(this.singleEditorMode$.value===!0)return;this.singleEditorMode$.next(!0),e?this.singleEditorModeConfig$.next(e):this.singleEditorModeConfig$.next(new Ut)}catch(t){this.loggingService.catch("Error in LiveStateService enableSingleEditorMode: ",t)}}disableSingleEditorMode(){try{if(this.singleEditorMode$.value===!1)return;this.singleEditorMode$.next(!1)}catch(e){this.loggingService.catch("Error in LiveStateService disableSingleEditorMode: ",e)}}getSingleEditorMode$(){return this.singleEditorMode$.asObservable()}getSingleEditorMode(){return this.singleEditorMode$.value}getSingleEditorModeConfig$(){return this.singleEditorModeConfig$.asObservable()}getSingleEditorModeConfig(){return this.singleEditorModeConfig$.value}enableAutoSyncState(){try{if(this.autoSyncState$.value===!0)return;this.autoSyncState$.next(!0)}catch(e){this.loggingService.catch("Error in LiveStateService enableAutoSyncState: ",e)}}disableAutoSyncState(){try{if(this.autoSyncState$.value===!1)return;this.autoSyncState$.next(!1)}catch(e){this.loggingService.catch("Error in LiveStateService disableAutoSyncState: ",e)}}getAutoSyncState$(){return this.autoSyncState$.asObservable()}getAutoSyncState(){return this.autoSyncState$.value}setEditorAccessTimeout(e){try{this.loggingService.log("%c[WB] Calling FUNCTION: setEditorAccessTimeout","color: green;"),e&&this.editorAccessTimeout$.next(e)}catch(t){this.loggingService.catch("Error in LiveStateService setEditorAccessTimeout: ",t)}}getEditorAccessTimeout$(){return this.editorAccessTimeout$.asObservable()}getEditorAccessTimeout(){return this.editorAccessTimeout$.value}enableEditorAccessTransferOnTimeOut(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: enableEditorAccessTransferOnTimeOut","color: green;"),this.editorAccessTransferOnTimeOut$.value===!0)return;this.editorAccessTransferOnTimeOut$.next(!0)}catch(e){this.loggingService.catch("Error in LiveStateService enableEditorAccessTransferOnTimeOut: ",e)}}disableEditorAccessTransferOnTimeOut(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: disableEditorAccessTransferOnTimeOut","color: green;"),this.editorAccessTransferOnTimeOut$.value===!1)return;this.editorAccessTransferOnTimeOut$.next(!1)}catch(e){this.loggingService.catch("Error in LiveStateService disableEditorAccessTransferOnTimeOut: ",e)}}getEditorAccessTransferOnTimeOut$(){return this.editorAccessTransferOnTimeOut$.asObservable()}getEditorAccessTransferOnTimeOut(){return this.editorAccessTransferOnTimeOut$.value}enableDefaultSingleEditorUI(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: enableDefaultSingleEditorUI","color: green;"),this.defaultSingleEditorUIEnabled$.value===!0)return;this.defaultSingleEditorUIEnabled$.next(!0)}catch(e){this.loggingService.catch("Error in LiveStateService enableDefaultSingleEditorUI: ",e)}}disableDefaultSingleEditorUI(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: disableDefaultSingleEditorUI","color: green;"),this.defaultSingleEditorUIEnabled$.value===!1)return;this.defaultSingleEditorUIEnabled$.next(!1)}catch(e){this.loggingService.catch("Error in LiveStateService disableDefaultSingleEditorUI: ",e)}}getDefaultSingleEditorUIEnabled$(){return this.defaultSingleEditorUIEnabled$.asObservable()}getDefaultSingleEditorUIEnabled(){return this.defaultSingleEditorUIEnabled$.value}setEditorAccessTimerInterval(e){try{this.loggingService.log("%c[WB] Calling FUNCTION: setEditorAccessTimerInterval","color: green;"),this.clearEditorAccessTimerInterval(),e>0&&(this.editorAccessTimer$.next({state:"inProgress",durationLeft:e}),this.editorAccessTimerInterval=setInterval(()=>{try{e-=1,e<0?this.clearEditorAccessTimerInterval():e?this.editorAccessTimer$.next({state:"inProgress",durationLeft:e}):this.editorAccessTimer$.next({state:"completed"})}catch(t){this.loggingService.catch("Error in LiveStateService setEditorAccessTimerCountdown interval: ",t),this.clearEditorAccessTimerInterval()}},1e3))}catch(t){this.loggingService.catch("Error in LiveStateService setEditorAccessTimerCountdown: ",t),this.clearEditorAccessTimerInterval()}}clearEditorAccessTimerInterval(){try{this.loggingService.log("%c[WB] Calling FUNCTION: clearEditorAccessTimerInterval","color: green;"),this.editorAccessTimerInterval&&(clearInterval(this.editorAccessTimerInterval),this.editorAccessTimerInterval=null,this.editorAccessTimer$.next({state:"idle"}))}catch(e){this.loggingService.catch("Error in LiveStateService clearEditorAccessTimerInterval: ",e)}}getEditorAccessTimer$(){return this.editorAccessTimer$.asObservable()}onServerConnectionStateChange$(){return this.serverConnectionState$.asObservable()}updateExternalUserPresence(e){try{this.loggingService.log("%c[WB] Calling FUNCTION: updateExternalUserPresence","color: green;"),this.externalUserPresence$.next(e)}catch(t){this.loggingService.catch("Error in LiveStateService updateExternalUserPresence: ",t)}}getExternalUserPresence$(){return this.externalUserPresence$.asObservable().pipe(ne(Ee))}getExternalUserPresence(){return this.externalUserPresence$.value}enableHeartbeat(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: enableHeartbeat","color: green;"),this.heartbeat$.value===!0)return;this.heartbeat$.next(!0)}catch(e){this.loggingService.catch("Error in LiveStateService enableHeartbeat: ",e)}}disableHeartbeat(){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: disableHeartbeat","color: green;"),this.heartbeat$.value===!1)return;this.heartbeat$.next(!1)}catch(e){this.loggingService.catch("Error in LiveStateService disableHeartbeat: ",e)}}detectLiveSyncInputs(){try{document.querySelectorAll(`[${ee.ATTRIBUTES.VELT_SYNC_STATE}]`)?.forEach(t=>{this.subscribeInputChanges(t)})}catch(e){this.loggingService.catch("Error in LiveStateService detectLiveSyncInputs: ",e)}}subscribeInputChanges(e){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: subscribeInputChanges","color: green;"),e){let t=e.tagName,i=this.domService.getXPath(e),s=Ie(i);if(this.inputChangeSubscriptionMap[s])this.loggingService.warn("subscription already exists",s,e);else{this.inputChangeSubscriptionMap[s]={id:s,element:e};let l;switch(t?.toLowerCase()){case"input":l=Le(e,"input").pipe(je(300)).subscribe(d=>{let a={value:d?.target?.value,tagName:d?.target?.tagName,type:d?.target?.type};this.setLiveStateSyncInputData(d?.target,a)});break;case"textarea":l=Le(e,"input").pipe(je(300)).subscribe(d=>{let a={value:d?.target?.value,tagName:d?.target?.tagName};this.setLiveStateSyncInputData(d?.target,a)});break;default:e.getAttribute("contenteditable")&&(l=Le(e,"input").pipe(je(300)).subscribe(d=>{let a={innerText:d?.target?.innerText,innerHTML:this.domService.sanitizeHtml(d?.target?.innerHTML),tagName:d?.target?.tagName,isContentEditable:!0};this.setLiveStateSyncInputData(d?.target,a)}));break}l&&(this.inputChangeSubscriptionMap[s]?.subscriptions||(this.inputChangeSubscriptionMap[s]={subscriptions:[]}),this.inputChangeSubscriptionMap[s].subscriptions?.push(l))}}}catch(t){this.loggingService.catch("Error in LiveStateService subscribeInputChanges: ",t)}}unsubscribeInputChanges(){try{this.loggingService.log("%c[WB] Calling FUNCTION: unsubscribeInputChanges","color: green;"),Object.keys(this.inputChangeSubscriptionMap).forEach(e=>{this.inputChangeSubscriptionMap[e]?.subscriptions?.forEach(i=>{i.unsubscribe()})}),this.inputChangeSubscriptionMap={}}catch(e){this.loggingService.catch("Error in LiveStateService unsubscribeInputChanges: ",e)}}setLiveStateSyncInputData(e,t){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: setLiveStateSyncInputData","color: green;"),this.user&&this.documentPaths?.liveState){let i=this.domService.getXPath(e),s=Ie(i),l={id:s,lastUpdated:this.timestamp,liveStateDataId:i,data:t,updatedBy:this.user,tabId:this.tabId};this.commonDbService.updateData({feature:"liveStateAutoSyncStateCurrent",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",skipFirestore:!0},data:JSON.parse(JSON.stringify(l))}),this.commonDbService.updateData({feature:"liveStateAutoSyncStateHistoryId",properties:{documentId:this.documentPaths?.documentId??"",organizationId:this.documentPaths?.organizationId??"",id:s,skipFirestore:!0},data:JSON.parse(JSON.stringify(l))})}}catch(i){this.loggingService.catch("Error in LiveStateService setLiveStateSyncInputData: ",i)}}updateLiveStateSyncInputDataLocally(e){try{this.loggingService.log("%c[WB] Calling FUNCTION: updateLiveStateSyncInputDataLocally","color: green;"),this.user&&Object.keys(e).forEach(t=>{let i=e[t],s=this.domService.getElementFromXPath(i?.liveStateDataId),l=!1;if(i?.updatedBy?.userSnippylyId!==this.user?.userSnippylyId)l=!0;else{let u=i?.tabId&&this.tabId&&i?.tabId!==this.tabId,d=s?.contains(document.activeElement);u&&!Pt()&&!d&&(l=!0)}if(l&&s)switch(s.value=i?.data?.value,s.tagName?.toLowerCase()){case"input":s.value=i?.data?.value;break;case"textarea":s.value=i?.data?.value;break;default:s.getAttribute("contenteditable")&&(s.innerHTML=this.domService.sanitizeHtml(i?.data?.innerHTML))}})}catch(t){this.loggingService.catch("Error in LiveStateService updateLiveStateSyncInputDataLocally: ",t)}}setSingleEditorModeContainerIds(e){this.singleEditorModeContainerIds$.next(e||[])}getSingleEditorModeContainerIds(){return this.singleEditorModeContainerIds$.asObservable()}isElementInsideSingleEditorModeContainerElements(e){try{this.loggingService.log("%c[WB] Calling FUNCTION: isElementInsideSingleEditorModeContainerElements","color: green;");let t=this.singleEditorModeContainerIds$.value,i=document.querySelectorAll(`[${ee.ATTRIBUTES.VELT_SINGLE_EDITOR_MODE_CONTAINER}]`);if(!t?.length&&!i?.length)return!0;if(t?.length)for(let s=0;s<t.length;s++){let l=document.getElementById(t[s]);if(l&&l.contains(e))return!0}if(i?.length)for(let s=0;s<i.length;s++){let l=i[s];if(l&&l.contains(e))return!0}return!1}catch(t){return this.loggingService.catch("Error in LiveStateService isElementInsideSingleEditorModeContainerElements: ",t),!1}}isSingleEditorModeDisabledForElement(e){try{if(this.loggingService.log("%c[WB] Calling FUNCTION: isSingleEditorModeDisabledForElement","color: green;"),e){if(e.getAttribute(ee.ATTRIBUTES.VELT_SYNC_ACCESS_DISABLED))return!0;{let i=e?.parentElement;if(i)return this.isSingleEditorModeDisabledForElement(i)}}return!1}catch(t){return this.loggingService.catch("Error in LiveStateService isSingleEditorModeDisabledForElement: ",t),!1}}updateOnDatabaseDisconnect(){return this.loggingService.log("%c[WB] Calling FUNCTION: updateOnDatabaseDisconnect","color: green;"),this.isUserEditor$().pipe(Ge(e=>{try{if(this.documentPaths?.liveStateSingleEditorMode){let t=this.realtimeAdapter.rtdbRef(this.db,`${this.documentPaths?.liveStateSingleEditorMode}`);e?.isEditor&&(!this.getSingleEditorModeConfig()?.singleTabEditor||e?.isEditorOnCurrentTab)?this.realtimeAdapter.rtdbOnDisconnectRemove("liveState",t):this.realtimeAdapter.rtdbOnDisconnectCancel("liveState",t)}}catch(t){this.loggingService.catch("Error in LiveStateService updateOnDatabaseDisconnect tap: ",t)}}))}updateServerStateOnDatabaseDisconnect(){return this.loggingService.log("%c[WB] Calling FUNCTION: updateServerStateOnDatabaseDisconnect","color: green;"),this.authService.getAuthState$().pipe(k(e=>!!e),y(e=>this.docService.getDocumentPaths$().pipe(D(t=>e))),Ge(e=>Q(this,null,function*(){try{if(this.connectionListenerUnsubscribe&&(this.connectionListenerUnsubscribe(),this.connectionListenerUnsubscribe=null),this.offlineTimer&&(clearTimeout(this.offlineTimer),this.offlineTimer=null),this.docService.getDocumentPaths()?.liveState&&e){let i=this.realtimeAdapter.rtdbRef(this.db,".info/connected"),s=!0,l=1500;this.connectionListenerUnsubscribe=this.realtimeAdapter.rtdbOnValue("liveState",i,u=>{let d=u.val();if(s&&d===!1){s=!1;return}s=!1,this.offlineTimer&&(clearTimeout(this.offlineTimer),this.offlineTimer=null),d?this.serverConnectionState$.value===K.OFFLINE&&this.serverConnectionState$.next(K.ONLINE):this.offlineTimer=setTimeout(()=>{this.serverConnectionState$.next(K.OFFLINE),this.offlineTimer=null},l)})}}catch(t){this.loggingService.catch("Error in updateServerStateOnDatabaseDisconnect:",t)}})))}signOutUser(e){return new Promise((t,i)=>{try{this.documentPaths?.liveStateSingleEditorMode&&e?this.commonDbService.getData({feature:"liveStateSingleEditorMode",properties:{documentId:this.documentPaths?.documentId,organizationId:this.documentPaths?.organizationId,skipFirestore:!0}}).then(s=>{s&&this.isUserEditor()?.isEditor&&(!this.getSingleEditorModeConfig()?.singleTabEditor||this.isUserEditor()?.isEditorOnCurrentTab)&&this.removeEditorAccess({metadata:{from:"signOutUser-liveStateService",reason:"User signed out"}}),t(null)}).catch(s=>{this.loggingService.catch("Error in signOutUser subscription: ",s),i(s)}):t(null)}catch(s){this.loggingService.catch("Error in signOutUser:",s),i(s)}})}getSemStats(){try{let e=!!this.authService?.getUser(),t=!!this.docService?.getDocumentPaths(),i=this.singleEditorMode$.value,s=!!this.singleEditorModeConfig$.value,l=this.isUserEditor(),u;this.singleEditorLiveStateData$.value&&typeof this.singleEditorLiveStateData$.value=="object"&&(u=this.liveStateUtilsService?.formatLiveStateSingleEditorModeData(JSON.parse(JSON.stringify(this.singleEditorLiveStateData$.value))));let d=this.getExternalUserPresence();return{userAvailable:e,documentPathsAvailable:t,singleEditorModeEnabled:i,singleEditorModeConfig:s,isEditor:l,singleEditorLiveStateData:u,userPresence:d}}catch(e){this.loggingService.catch("Error in LiveStateService getSemStats: ",e)}}get timestamp(){return this.commonDbService.getServerTimestamp()}};r.\u0275fac=function(t){return new(t||r)(L(Lt),L(Xe),L(Oe),L(Ft),L(Ze),L(qt),L($t),L(De),L(Qt),L(zt),L(c),L(Gt),L(nt),L(Bt),L(et),L(Zt),L(Ye),L(jt))},r.\u0275prov=Ae({token:r,factory:r.\u0275fac,providedIn:"root"});let n=r;return n})();var H=class{constructor(){this.singleEditorMode=!1,this.defaultSingleEditorUIEnabled=!1,this.editAccessRequested=!1,this.leaderName="",this.type="reader",this.requestEditorAccessCountdown=0,this.shadowDom=!0,this.requestEditorAccess=()=>{},this.cancelEditorAccessRequest=()=>{},this.rejectEditorAccessRequest=()=>{},this.acceptEditorAccessRequest=()=>{},this.editCurrentTab=()=>{}}};var ti=n=>({componentConfigSignal:n}),fi=(n,r)=>({condition:n,data:r}),Ci=(n,r,o,e,t)=>({template:n,context:r,componentName:"velt-single-editor-mode-panel-countdown-wireframe",variant:o,setIfCondition:e,componentElementRef:t});function bi(n,r){if(n&1&&(b(0),X(1),_()),n&2){let o=g(3).ngIf;h(),Z(" ",o.requestEditorAccessCountdown," ")}}function _i(n,r){if(n&1&&(R(0,"span",3),S(1,bi,2,1,"ng-container",4),N()),n&2){let o=g(2).ngIf,e=g();h(),v("veltDynamicTemplate",G(3,Ci,e.template,x(1,ti,e.componentConfigSignal),o==null?null:o.variant,e.setIfCondition.bind(e),e.elementRef))}}function Ii(n,r){if(n&1&&(b(0),S(1,_i,2,9,"span",2),_()),n&2){let o=g().ngIf;h(),v("ngIf",o.type==="editor"&&o.requestEditorAccessCountdown)}}function yi(n,r){if(n&1&&(b(0),S(1,Ii,2,1,"ng-container",1),_()),n&2){let o=g();h(),v("veltIf",j(3,fi,o.conditionSignal(),x(1,ti,o.componentConfigSignal)))}}var xe=(()=>{let r=class r extends te{constructor(e,t,i){super(e,t,i),this.elementRef=e,this.dynamicDataService=t,this.loggingService=i,this.componentId="velt-single-editor-mode-panel-countdown";try{super.initializeComponentConfigSignal(new H)}catch(s){this.loggingService.catch("Error in SingleEditorModePanelCountdownComponent constructor:",s)}}ngOnInit(){try{super.ngOnInit(),this.setupA11yAttributes()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelCountdownComponent ngOnInit: ",e)}}ngOnDestroy(){try{super.ngOnDestroy()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelCountdownComponent ngOnDestroy: ",e)}}setupA11yAttributes(){try{this.elementRef.nativeElement.setAttribute("data-testid",this.componentId+"-container")}catch(e){this.loggingService.catch("Error in SingleEditorModePanelCountdownComponent setupA11yAttributes:",e)}}};r.\u0275fac=function(t){return new(t||r)(E(F),E(U),E(c))},r.\u0275cmp=q({type:r,selectors:[["velt-single-editor-mode-panel-countdown"]],standalone:!1,features:[$],decls:1,vars:1,consts:[[4,"ngIf"],[4,"veltIf"],["class","velt-single-editor-mode-panel-countdown-text countdown-text","data-velt-ignore","",4,"ngIf"],["data-velt-ignore","",1,"velt-single-editor-mode-panel-countdown-text","countdown-text"],[4,"veltDynamicTemplate"]],template:function(t,i){t&1&&S(0,yi,2,6,"ng-container",0),t&2&&v("ngIf",i.componentConfigSignal())},dependencies:[B,V,W],styles:["html[_ngcontent-%COMP%]{--velt-base-rem-unit: 1}*[data-snippyly-element=true][_ngcontent-%COMP%], *[data-velt-element=true][_ngcontent-%COMP%]{font-family:var(--velt-default-font-family)}velt-wireframe[_ngcontent-%COMP%]{display:none!important}body.velt-pin-dragging[_ngcontent-%COMP%] iframe[_ngcontent-%COMP%]{pointer-events:none!important}[_nghost-%COMP%]:empty{display:none}.velt-single-editor-mode-panel-countdown-text[_ngcontent-%COMP%]{background:var(--velt-accent);color:var(--velt-white);display:flex;justify-content:center;align-items:center;padding:var(--velt-spacing-xs);border-radius:var(--velt-border-radius-full);width:calc((1rem + 0px) * var(--velt-base-rem-unit));height:calc((1rem + 0px) * var(--velt-base-rem-unit));font-style:normal;font-weight:600;font-size:var(--velt-font-size-2xs)}"],changeDetection:0});let n=r;return n})();var ii=n=>({componentConfigSignal:n}),Ai=(n,r)=>({condition:n,data:r}),Di=(n,r,o,e,t)=>({template:n,context:r,componentName:"velt-single-editor-mode-panel-edit-here-wireframe",variant:o,setIfCondition:e,componentElementRef:t});function Oi(n,r){n&1&&(b(0),X(1),J(2,"translate"),_()),n&2&&(h(),Z(" ",z(2,1,"Edit here")," "))}function Mi(n,r){if(n&1){let o=ge();R(0,"button",3),ue("click",function(){le(o);let t=g(2).ngIf;return de(t.editCurrentTab())}),S(1,Oi,3,3,"ng-container",4),N()}if(n&2){let o=g(2).ngIf,e=g();h(),v("veltDynamicTemplate",G(3,Di,e.template,x(1,ii,e.componentConfigSignal),o==null?null:o.variant,e.setIfCondition.bind(e),e.elementRef))}}function Li(n,r){if(n&1&&(b(0),S(1,Mi,2,9,"button",2),_()),n&2){let o=g().ngIf;h(),v("ngIf",o.type==="editor"&&(o.singleEditorConfig==null?null:o.singleEditorConfig.singleTabEditor)&&!(o.isUserEditor!=null&&o.isUserEditor.isEditorOnCurrentTab)&&!o.requestEditorAccessCountdown)}}function xi(n,r){if(n&1&&(b(0),S(1,Li,2,1,"ng-container",1),_()),n&2){let o=g();h(),v("veltIf",j(3,Ai,o.conditionSignal(),x(1,ii,o.componentConfigSignal)))}}var Ue=(()=>{let r=class r extends te{constructor(e,t,i){super(e,t,i),this.elementRef=e,this.dynamicDataService=t,this.loggingService=i,this.componentId="velt-single-editor-mode-panel-edit-here";try{super.initializeComponentConfigSignal(new H)}catch(s){this.loggingService.catch("Error in SingleEditorModePanelEditHereComponent constructor:",s)}}ngOnInit(){try{super.ngOnInit(),this.setupA11yAttributes()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelEditHereComponent ngOnInit: ",e)}}ngOnDestroy(){try{super.ngOnDestroy()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelEditHereComponent ngOnDestroy: ",e)}}setupA11yAttributes(){try{this.elementRef.nativeElement.setAttribute("data-testid",this.componentId+"-container")}catch(e){this.loggingService.catch("Error in SingleEditorModePanelEditHereComponent setupA11yAttributes:",e)}}};r.\u0275fac=function(t){return new(t||r)(E(F),E(U),E(c))},r.\u0275cmp=q({type:r,selectors:[["velt-single-editor-mode-panel-edit-here"]],standalone:!1,features:[$],decls:1,vars:1,consts:[[4,"ngIf"],[4,"veltIf"],["class","velt-single-editor-mode-panel-btn follow-btn","data-velt-ignore","",3,"click",4,"ngIf"],["data-velt-ignore","",1,"velt-single-editor-mode-panel-btn","follow-btn",3,"click"],[4,"veltDynamicTemplate"]],template:function(t,i){t&1&&S(0,xi,2,6,"ng-container",0),t&2&&v("ngIf",i.componentConfigSignal())},dependencies:[B,V,W,re],styles:["html[_ngcontent-%COMP%]{--velt-base-rem-unit: 1}*[data-snippyly-element=true][_ngcontent-%COMP%], *[data-velt-element=true][_ngcontent-%COMP%]{font-family:var(--velt-default-font-family)}velt-wireframe[_ngcontent-%COMP%]{display:none!important}body.velt-pin-dragging[_ngcontent-%COMP%] iframe[_ngcontent-%COMP%]{pointer-events:none!important}[_nghost-%COMP%]:empty{display:none}.velt-single-editor-mode-panel-btn[_ngcontent-%COMP%]{background-color:var(--velt-background-3);color:var(--velt-text-0);padding:var(--velt-spacing-sm) var(--velt-spacing-md);border-radius:var(--velt-border-radius-full);display:inline-flex;justify-content:center;align-items:center;border:none;font-weight:600;font-size:var(--velt-font-size-sm);cursor:pointer;pointer-events:all}.velt-single-editor-mode-panel-btn[_ngcontent-%COMP%]:hover{transition:background-color .5s;background-color:var(--velt-background-5)}"],changeDetection:0});let n=r;return n})();var ni=n=>({componentConfigSignal:n}),Ri=(n,r)=>({condition:n,data:r}),Ni=(n,r,o,e,t)=>({template:n,context:r,componentName:"velt-single-editor-mode-panel-editor-text-wireframe",variant:o,setIfCondition:e,componentElementRef:t});function Pi(n,r){if(n&1&&(b(0),X(1),J(2,"translate"),J(3,"translate"),J(4,"translate"),_()),n&2){let o=g(3).ngIf;h(),Z(" ",o.requestEditorAccessCountdown?((o.singleEditorLiveStateData==null||o.singleEditorLiveStateData.requestEditorAccess==null||o.singleEditorLiveStateData.requestEditorAccess.user==null?null:o.singleEditorLiveStateData.requestEditorAccess.user.name)||(o.singleEditorLiveStateData==null||o.singleEditorLiveStateData.requestEditorAccess==null||o.singleEditorLiveStateData.requestEditorAccess.user==null?null:o.singleEditorLiveStateData.requestEditorAccess.user.email))+" "+z(2,1,"requested edit access."):!(o.singleEditorConfig!=null&&o.singleEditorConfig.singleTabEditor)||o.isUserEditor!=null&&o.isUserEditor.isEditorOnCurrentTab?z(3,3,"You are editing."):z(4,5,"You are editing on different tab.")," ")}}function wi(n,r){if(n&1&&(R(0,"span",3),S(1,Pi,5,7,"ng-container",4),N()),n&2){let o=g(2).ngIf,e=g();h(),v("veltDynamicTemplate",G(3,Ni,e.template,x(1,ni,e.componentConfigSignal),o==null?null:o.variant,e.setIfCondition.bind(e),e.elementRef))}}function ki(n,r){if(n&1&&(b(0),S(1,wi,2,9,"span",2),_()),n&2){let o=g().ngIf;h(),v("ngIf",o.type==="editor")}}function Fi(n,r){if(n&1&&(b(0),S(1,ki,2,1,"ng-container",1),_()),n&2){let o=g();h(),v("veltIf",j(3,Ri,o.conditionSignal(),x(1,ni,o.componentConfigSignal)))}}var Re=(()=>{let r=class r extends te{constructor(e,t,i){super(e,t,i),this.elementRef=e,this.dynamicDataService=t,this.loggingService=i,this.componentId="velt-single-editor-mode-panel-editor-text";try{super.initializeComponentConfigSignal(new H)}catch(s){this.loggingService.catch("Error in SingleEditorModePanelEditorTextComponent constructor:",s)}}ngOnInit(){try{super.ngOnInit(),this.setupA11yAttributes()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelEditorTextComponent ngOnInit: ",e)}}ngOnDestroy(){try{super.ngOnDestroy()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelEditorTextComponent ngOnDestroy: ",e)}}setupA11yAttributes(){try{this.elementRef.nativeElement.setAttribute("data-testid",this.componentId+"-container")}catch(e){this.loggingService.catch("Error in SingleEditorModePanelEditorTextComponent setupA11yAttributes:",e)}}};r.\u0275fac=function(t){return new(t||r)(E(F),E(U),E(c))},r.\u0275cmp=q({type:r,selectors:[["velt-single-editor-mode-panel-editor-text"]],standalone:!1,features:[$],decls:1,vars:1,consts:[[4,"ngIf"],[4,"veltIf"],["class","velt-single-editor-mode-panel-text follow-text","data-velt-ignore","",4,"ngIf"],["data-velt-ignore","",1,"velt-single-editor-mode-panel-text","follow-text"],[4,"veltDynamicTemplate"]],template:function(t,i){t&1&&S(0,Fi,2,6,"ng-container",0),t&2&&v("ngIf",i.componentConfigSignal())},dependencies:[B,V,W,re],styles:["[_nghost-%COMP%]:empty{display:none}"],changeDetection:0});let n=r;return n})();var ri=n=>({componentConfigSignal:n}),$i=(n,r)=>({condition:n,data:r}),Bi=(n,r,o,e,t)=>({template:n,context:r,componentName:"velt-single-editor-mode-panel-viewer-text-wireframe",variant:o,setIfCondition:e,componentElementRef:t});function ji(n,r){if(n&1&&(b(0),X(1),J(2,"translate"),_()),n&2){let o=g(3).ngIf;h(),Z(" ",o.leaderName+" "+z(2,1,"is editing.")," ")}}function Gi(n,r){if(n&1&&(R(0,"span",3),S(1,ji,3,3,"ng-container",4),N()),n&2){let o=g(2).ngIf,e=g();h(),v("veltDynamicTemplate",G(3,Bi,e.template,x(1,ri,e.componentConfigSignal),o==null?null:o.variant,e.setIfCondition.bind(e),e.elementRef))}}function Wi(n,r){if(n&1&&(b(0),S(1,Gi,2,9,"span",2),_()),n&2){let o=g().ngIf;h(),v("ngIf",o.type==="reader")}}function Vi(n,r){if(n&1&&(b(0),S(1,Wi,2,1,"ng-container",1),_()),n&2){let o=g();h(),v("veltIf",j(3,$i,o.conditionSignal(),x(1,ri,o.componentConfigSignal)))}}var Ne=(()=>{let r=class r extends te{constructor(e,t,i){super(e,t,i),this.elementRef=e,this.dynamicDataService=t,this.loggingService=i,this.componentId="velt-single-editor-mode-panel-viewer-text";try{super.initializeComponentConfigSignal(new H)}catch(s){this.loggingService.catch("Error in SingleEditorModePanelViewerTextComponent constructor:",s)}}ngOnInit(){try{super.ngOnInit(),this.setupA11yAttributes()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelViewerTextComponent ngOnInit: ",e)}}ngOnDestroy(){try{super.ngOnDestroy()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelViewerTextComponent ngOnDestroy: ",e)}}setupA11yAttributes(){try{this.elementRef.nativeElement.setAttribute("data-testid",this.componentId+"-container")}catch(e){this.loggingService.catch("Error in SingleEditorModePanelViewerTextComponent setupA11yAttributes:",e)}}};r.\u0275fac=function(t){return new(t||r)(E(F),E(U),E(c))},r.\u0275cmp=q({type:r,selectors:[["velt-single-editor-mode-panel-viewer-text"]],standalone:!1,features:[$],decls:1,vars:1,consts:[[4,"ngIf"],[4,"veltIf"],["class","velt-single-editor-mode-panel-text follow-text","data-velt-ignore","",4,"ngIf"],["data-velt-ignore","",1,"velt-single-editor-mode-panel-text","follow-text"],[4,"veltDynamicTemplate"]],template:function(t,i){t&1&&S(0,Vi,2,6,"ng-container",0),t&2&&v("ngIf",i.componentConfigSignal())},dependencies:[B,V,W,re],styles:["[_nghost-%COMP%]:empty{display:none}"],changeDetection:0});let n=r;return n})();var oi=n=>({componentConfigSignal:n}),Ji=(n,r)=>({condition:n,data:r}),zi=(n,r,o,e,t)=>({template:n,context:r,componentName:"velt-single-editor-mode-panel-reject-request-wireframe",variant:o,setIfCondition:e,componentElementRef:t});function Ki(n,r){n&1&&(b(0),X(1),J(2,"translate"),_()),n&2&&(h(),Z(" ",z(2,1,"Reject Request")," "))}function Qi(n,r){if(n&1){let o=ge();R(0,"button",3),ue("click",function(){le(o);let t=g(2).ngIf;return de(t.rejectEditorAccessRequest())}),S(1,Ki,3,3,"ng-container",4),N()}if(n&2){let o=g(2).ngIf,e=g();h(),v("veltDynamicTemplate",G(3,zi,e.template,x(1,oi,e.componentConfigSignal),o==null?null:o.variant,e.setIfCondition.bind(e),e.elementRef))}}function Yi(n,r){if(n&1&&(b(0),S(1,Qi,2,9,"button",2),_()),n&2){let o=g().ngIf;h(),v("ngIf",o.type==="editor"&&o.requestEditorAccessCountdown)}}function Xi(n,r){if(n&1&&(b(0),S(1,Yi,2,1,"ng-container",1),_()),n&2){let o=g();h(),v("veltIf",j(3,Ji,o.conditionSignal(),x(1,oi,o.componentConfigSignal)))}}var Pe=(()=>{let r=class r extends te{constructor(e,t,i){super(e,t,i),this.elementRef=e,this.dynamicDataService=t,this.loggingService=i,this.componentId="velt-single-editor-mode-panel-reject-request";try{super.initializeComponentConfigSignal(new H)}catch(s){this.loggingService.catch("Error in SingleEditorModePanelRejectRequestComponent constructor:",s)}}ngOnInit(){try{super.ngOnInit(),this.setupA11yAttributes()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelRejectRequestComponent ngOnInit: ",e)}}ngOnDestroy(){try{super.ngOnDestroy()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelRejectRequestComponent ngOnDestroy: ",e)}}setupA11yAttributes(){try{this.elementRef.nativeElement.setAttribute("data-testid",this.componentId+"-container")}catch(e){this.loggingService.catch("Error in SingleEditorModePanelRejectRequestComponent setupA11yAttributes:",e)}}};r.\u0275fac=function(t){return new(t||r)(E(F),E(U),E(c))},r.\u0275cmp=q({type:r,selectors:[["velt-single-editor-mode-panel-reject-request"]],standalone:!1,features:[$],decls:1,vars:1,consts:[[4,"ngIf"],[4,"veltIf"],["class","velt-single-editor-mode-panel-btn follow-btn","data-velt-ignore","",3,"click",4,"ngIf"],["data-velt-ignore","",1,"velt-single-editor-mode-panel-btn","follow-btn",3,"click"],[4,"veltDynamicTemplate"]],template:function(t,i){t&1&&S(0,Xi,2,6,"ng-container",0),t&2&&v("ngIf",i.componentConfigSignal())},dependencies:[B,V,W,re],styles:["html[_ngcontent-%COMP%]{--velt-base-rem-unit: 1}*[data-snippyly-element=true][_ngcontent-%COMP%], *[data-velt-element=true][_ngcontent-%COMP%]{font-family:var(--velt-default-font-family)}velt-wireframe[_ngcontent-%COMP%]{display:none!important}body.velt-pin-dragging[_ngcontent-%COMP%] iframe[_ngcontent-%COMP%]{pointer-events:none!important}[_nghost-%COMP%]:empty{display:none}.velt-single-editor-mode-panel-btn[_ngcontent-%COMP%]{background-color:var(--velt-background-3);color:var(--velt-text-0);padding:var(--velt-spacing-sm) var(--velt-spacing-md);border-radius:var(--velt-border-radius-full);display:inline-flex;justify-content:center;align-items:center;border:none;font-weight:600;font-size:var(--velt-font-size-sm);cursor:pointer;pointer-events:all}.velt-single-editor-mode-panel-btn[_ngcontent-%COMP%]:hover{transition:background-color .5s;background-color:var(--velt-background-5)}"],changeDetection:0});let n=r;return n})();var si=n=>({componentConfigSignal:n}),en=(n,r)=>({condition:n,data:r}),tn=(n,r,o,e,t)=>({template:n,context:r,componentName:"velt-single-editor-mode-panel-request-access-wireframe",variant:o,setIfCondition:e,componentElementRef:t});function nn(n,r){if(n&1&&(b(0),X(1),J(2,"translate"),J(3,"translate"),_()),n&2){let o=g(3).ngIf;h(),Z(" ",o.editAccessRequested?z(2,1,"Access Requested"):z(3,3,"Request access")," ")}}function rn(n,r){if(n&1){let o=ge();R(0,"button",3),ue("click",function(){le(o);let t=g(2).ngIf;return de(t.requestEditorAccess())}),S(1,nn,4,5,"ng-container",4),N()}if(n&2){let o=g(2).ngIf,e=g();h(),v("veltDynamicTemplate",G(3,tn,e.template,x(1,si,e.componentConfigSignal),o==null?null:o.variant,e.setIfCondition.bind(e),e.elementRef))}}function on(n,r){if(n&1&&(b(0),S(1,rn,2,9,"button",2),_()),n&2){let o=g().ngIf;h(),v("ngIf",o.type!=="editor")}}function sn(n,r){if(n&1&&(b(0),S(1,on,2,1,"ng-container",1),_()),n&2){let o=g();h(),v("veltIf",j(3,en,o.conditionSignal(),x(1,si,o.componentConfigSignal)))}}var we=(()=>{let r=class r extends te{constructor(e,t,i){super(e,t,i),this.elementRef=e,this.dynamicDataService=t,this.loggingService=i,this.componentId="velt-single-editor-mode-panel-request-access";try{super.initializeComponentConfigSignal(new H)}catch(s){this.loggingService.catch("Error in SingleEditorModePanelRequestAccessComponent constructor:",s)}}ngOnInit(){try{super.ngOnInit(),this.setupA11yAttributes()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelRequestAccessComponent ngOnInit: ",e)}}ngOnDestroy(){try{super.ngOnDestroy()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelRequestAccessComponent ngOnDestroy: ",e)}}setupA11yAttributes(){try{this.elementRef.nativeElement.setAttribute("data-testid",this.componentId+"-container")}catch(e){this.loggingService.catch("Error in SingleEditorModePanelRequestAccessComponent setupA11yAttributes:",e)}}};r.\u0275fac=function(t){return new(t||r)(E(F),E(U),E(c))},r.\u0275cmp=q({type:r,selectors:[["velt-single-editor-mode-panel-request-access"]],standalone:!1,features:[$],decls:1,vars:1,consts:[[4,"ngIf"],[4,"veltIf"],["class","velt-single-editor-mode-panel-btn follow-btn","data-velt-ignore","",3,"click",4,"ngIf"],["data-velt-ignore","",1,"velt-single-editor-mode-panel-btn","follow-btn",3,"click"],[4,"veltDynamicTemplate"]],template:function(t,i){t&1&&S(0,sn,2,6,"ng-container",0),t&2&&v("ngIf",i.componentConfigSignal())},dependencies:[B,V,W,re],styles:["html[_ngcontent-%COMP%]{--velt-base-rem-unit: 1}*[data-snippyly-element=true][_ngcontent-%COMP%], *[data-velt-element=true][_ngcontent-%COMP%]{font-family:var(--velt-default-font-family)}velt-wireframe[_ngcontent-%COMP%]{display:none!important}body.velt-pin-dragging[_ngcontent-%COMP%] iframe[_ngcontent-%COMP%]{pointer-events:none!important}[_nghost-%COMP%]:empty{display:none}.velt-single-editor-mode-panel-btn[_ngcontent-%COMP%]{background-color:var(--velt-background-3);color:var(--velt-text-0);padding:var(--velt-spacing-sm) var(--velt-spacing-md);border-radius:var(--velt-border-radius-full);display:inline-flex;justify-content:center;align-items:center;border:none;font-weight:600;font-size:var(--velt-font-size-sm);cursor:pointer;pointer-events:all}.velt-single-editor-mode-panel-btn[_ngcontent-%COMP%]:hover{transition:background-color .5s;background-color:var(--velt-background-5)}"],changeDetection:0});let n=r;return n})();var dt=n=>({componentConfigSignal:n}),ai=(n,r)=>({condition:n,data:r}),ln=(n,r,o,e,t)=>({template:n,context:r,componentName:"velt-single-editor-mode-panel-wireframe",variant:o,setIfCondition:e,componentElementRef:t});function dn(n,r){n&1&&yt(0)}function gn(n,r){if(n&1&&(R(0,"velt-shadow-dom-internal"),S(1,dn,1,0,"ng-container",4),N()),n&2){g(3);let o=at(2);h(),v("ngTemplateOutlet",o)}}function un(n,r){if(n&1&&(b(0),S(1,gn,2,1,"velt-shadow-dom-internal",3),_()),n&2){let o=g().ngIf,e=g(),t=at(2);h(),v("ngIf",o.shadowDom&&!e.template||e.template&&e.isExplicitShadowDom)("ngIfElse",t)}}function vn(n,r){if(n&1&&(b(0),S(1,un,2,2,"ng-container",2),_()),n&2){let o=g();h(),v("veltIf",j(3,ai,o.conditionSignal(),x(1,dt,o.componentConfigSignal)))}}function mn(n,r){if(n&1&&(b(0),R(1,"div",8),Ve(2,"velt-single-editor-mode-panel-viewer-text",9)(3,"velt-single-editor-mode-panel-editor-text",9)(4,"velt-single-editor-mode-panel-countdown",9)(5,"velt-single-editor-mode-panel-request-access",9)(6,"velt-single-editor-mode-panel-reject-request",9)(7,"velt-single-editor-mode-panel-edit-here",9),N(),_()),n&2){let o=g(6);h(2),v("componentConfigSignal",o.componentConfigSignal),h(),v("componentConfigSignal",o.componentConfigSignal),h(),v("componentConfigSignal",o.componentConfigSignal),h(),v("componentConfigSignal",o.componentConfigSignal),h(),v("componentConfigSignal",o.componentConfigSignal),h(),v("componentConfigSignal",o.componentConfigSignal)}}function hn(n,r){if(n&1&&(b(0),S(1,mn,8,6,"ng-container",7),_()),n&2){let o=g(3).ngIf,e=g(2);h(),v("veltDynamicTemplate",G(3,ln,e.template,x(1,dt,e.componentConfigSignal),o==null?null:o.variant,e.setIfCondition.bind(e),e.elementRef))}}function Sn(n,r){if(n&1&&(R(0,"div",6),S(1,hn,2,9,"ng-container",2),N()),n&2){let o=g(2).ngIf,e=g(2);Tt("velt-single-editor-mode-panel-container-no-pointer",o.type==="editor")("no-pointer",o.type==="editor"),h(),v("veltIf",j(7,ai,e.conditionSignal(),x(5,dt,e.componentConfigSignal)))}}function pn(n,r){if(n&1&&(b(0),S(1,Sn,2,10,"div",5),_()),n&2){let o=g().ngIf;h(),v("ngIf",o.leaderName!==""||o.type==="editor")}}function En(n,r){if(n&1&&(b(0),S(1,pn,2,1,"ng-container",1),_()),n&2){let o=r.ngIf;h(),v("ngIf",o.singleEditorMode)}}function fn(n,r){if(n&1&&S(0,En,2,1,"ng-container",1),n&2){let o=g();v("ngIf",o.componentConfigSignal())}}var ye=(()=>{let r=class r extends it{set _shadowDom(e){try{let t=e;typeof e=="string"&&(t=JSON.parse(e)),this.isExplicitShadowDom=!!t,this.componentConfigSignal.update(i=>(i=A(f({},i),{shadowDom:t}),i))}catch(t){this.loggingService.catch("Error in SingleEditorModePanelComponent _shadowDom: ",t)}}constructor(e,t,i,s,l,u,d){super(e,l,void 0,void 0,void 0,u,s),this.elementRef=e,this.authService=t,this.liveStateService=i,this.loggingService=s,this.themeService=l,this.dynamicDataService=u,this.wireframeService=d,this.isExplicitShadowDom=!1,this.subscriptions=[],this.componentConfigSignal=We({singleEditorMode:!1,defaultSingleEditorUIEnabled:!1,editAccessRequested:!1,leaderName:"",type:"reader",requestEditorAccessCountdown:0,singleEditorLiveStateData:null,singleEditorConfig:null,isUserEditor:null,variant:this.variant,shadowDom:!0,requestEditorAccess:this.requestEditorAccess.bind(this),cancelEditorAccessRequest:this.cancelEditorAccessRequest.bind(this),rejectEditorAccessRequest:this.rejectEditorAccessRequest.bind(this),acceptEditorAccessRequest:this.acceptEditorAccessRequest.bind(this),editCurrentTab:this.editCurrentTab.bind(this)}),this.componentId="velt-single-editor-mode-panel";try{this.loggingService.log("%c[WB] Calling FUNCTION: SingleEditorModePanelComponent constructor","color: green;"),this.subscriptions.push(this.liveStateService.getSingleEditorMode$().subscribe(a=>{this.componentConfigSignal.update(C=>A(f({},C),{singleEditorMode:a}))})),this.subscriptions.push(this.liveStateService.getDefaultSingleEditorUIEnabled$().subscribe(a=>{this.componentConfigSignal.update(C=>A(f({},C),{defaultSingleEditorUIEnabled:a}))})),this.subscriptions.push(this.liveStateService.getSingleEditorModeConfig$().subscribe(a=>{this.componentConfigSignal.update(C=>A(f({},C),{singleEditorConfig:a}))})),this.subscriptions.push(this.liveStateService.isUserEditor$().subscribe(a=>{this.componentConfigSignal.update(C=>A(f({},C),{isUserEditor:a}))})),this.subscriptions.push(this.liveStateService.getSingleEditorLiveStateData$().subscribe(a=>{let C=this.componentConfigSignal().singleEditorLiveStateData?.requestEditorAccess?.user?.userId,P=a?.requestEditorAccess?.user?.userId;if(C&&P&&C!==P&&this.componentConfigSignal().requestEditorAccessCountdown&&this.removeRequestEditorAccessCountdown(),this.componentConfigSignal.update(O=>A(f({},O),{singleEditorLiveStateData:a})),a){this.componentConfigSignal.update(w=>A(f({},w),{leaderName:a?.editor?.name||a?.editor?.email||""}));let O=this.authService.getUser();O?.userId===a?.editor?.userId?this.componentConfigSignal.update(w=>A(f({},w),{type:"editor"})):this.componentConfigSignal.update(w=>A(f({},w),{type:"reader"})),O?.userId===a?.requestEditorAccess?.user?.userId&&a?.requestEditorAccess?.status==="pending"?this.componentConfigSignal.update(w=>A(f({},w),{editAccessRequested:!0})):this.componentConfigSignal.update(w=>A(f({},w),{editAccessRequested:!1})),this.componentConfigSignal().type==="editor"&&!this.componentConfigSignal().requestEditorAccessCountdown&&a?.requestEditorAccess?.status==="pending"?this.showRequestEditorAccessCountdown():this.removeRequestEditorAccessCountdown()}}))}catch(a){this.loggingService.catch("Error in SingleEditorModePanelComponent constructor: ",a)}}ngOnInit(){try{this.loggingService.log("%c[WB] Calling FUNCTION: ngOnInit","color: green;"),super.ngOnInit(),this.setupA11yAttributes();let e="velt-single-editor-mode-panel-wireframe";this.variant&&(e+=`---${this.variant}`),this.wireframeService.getWireframe$(e).subscribe(t=>{if(t){let i=document.createElement(t.tagName);i.innerHTML=t.innerHTML,this.template=i}})}catch(e){this.loggingService.catch("Error in SingleEditorModePanelComponent ngOnInit: ",e)}}ngOnDestroy(){try{super.ngOnDestroy(),this.subscriptions.forEach(e=>{e.unsubscribe()})}catch(e){this.loggingService.catch("Error in SingleEditorModePanelComponent ngOnDestroy: ",e)}}ngOnChanges(e){try{super.ngOnChanges(e),e&&Object.keys(e).forEach(t=>{this.componentConfigSignal.update(i=>(i=A(f({},i),{[t]:e[t].currentValue}),i))})}catch(t){this.loggingService.catch("Error in SingleEditorModePanelComponent ngOnChanges: ",t)}}setupA11yAttributes(){try{this.elementRef.nativeElement.setAttribute("data-testid",this.componentId+"-container")}catch(e){this.loggingService.catch("Error in SingleEditorModePanelComponent setupA11yAttributes:",e)}}showRequestEditorAccessCountdown(){try{this.loggingService.log("%c[WB] Calling FUNCTION: showRequestEditorAccessCountdown","color: green;"),this.componentConfigSignal.update(e=>(e=A(f({},e),{requestEditorAccessCountdown:e.singleEditorLiveStateData?.requestEditorAccess?.editorAccessTimeout||ee.LIVE_STATE_REQUEST_EDITOR_ACCESS_WAIT_TIME}),e)),this.interval=setInterval(()=>{this.componentConfigSignal.update(e=>A(f({},e),{requestEditorAccessCountdown:e.requestEditorAccessCountdown-1})),this.componentConfigSignal().requestEditorAccessCountdown<=0&&clearInterval(this.interval)},1e3)}catch(e){this.loggingService.catch("Error in SingleEditorModePanelComponent showRequestEditorAccessCountdown: ",e)}}removeRequestEditorAccessCountdown(){try{this.loggingService.log("%c[WB] Calling FUNCTION: removeRequestEditorAccessCountdown","color: green;"),this.componentConfigSignal.update(e=>A(f({},e),{requestEditorAccessCountdown:0})),clearInterval(this.interval)}catch(e){this.loggingService.catch("Error in SingleEditorModePanelComponent removeRequestEditorAccessCountdown: ",e)}}requestEditorAccess(){try{this.loggingService.log("%c[WB] Calling FUNCTION: requestEditorAccess","color: green;"),this.componentConfigSignal().editAccessRequested||this.liveStateService.requestEditorAccess().subscribe()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelComponent requestEditorAccess: ",e)}}cancelEditorAccessRequest(){try{this.loggingService.log("%c[WB] Calling FUNCTION: cancelEditorAccessRequest","color: green;"),this.liveStateService.cancelEditorAccessRequest()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelComponent cancelEditorAccessRequest: ",e)}}acceptEditorAccessRequest(){try{this.loggingService.log("%c[WB] Calling FUNCTION: acceptEditorAccessRequest","color: green;"),this.liveStateService.acceptEditorAccessRequest()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelComponent acceptEditorAccessRequest: ",e)}}rejectEditorAccessRequest(){try{this.loggingService.log("%c[WB] Calling FUNCTION: rejectEditorAccessRequest","color: green;"),this.liveStateService.rejectEditorAccessRequest()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelComponent rejectEditorAccessRequest: ",e)}}editCurrentTab(){try{this.loggingService.log("%c[WB] Calling FUNCTION: editCurrentTab","color: green;"),this.liveStateService.editCurrentTab()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelComponent editCurrentTab: ",e)}}};r.\u0275fac=function(t){return new(t||r)(E(F),E(Oe),E(T),E(c),E(tt),E(U),E(Wt))},r.\u0275cmp=q({type:r,selectors:[["velt-single-editor-mode-panel"]],inputs:{variant:"variant",_shadowDom:[0,"shadowDom","_shadowDom"]},standalone:!1,features:[He([U]),$,bt],decls:3,vars:1,consts:[["liveStateSyncPanelRef",""],[4,"ngIf"],[4,"veltIf"],[4,"ngIf","ngIfElse"],[4,"ngTemplateOutlet"],["data-velt-ignore","","class","velt-single-editor-mode-panel-container single-editor-mode-panel-container",3,"velt-single-editor-mode-panel-container-no-pointer","no-pointer",4,"ngIf"],["data-velt-ignore","",1,"velt-single-editor-mode-panel-container","single-editor-mode-panel-container"],[4,"veltDynamicTemplate"],["data-velt-ignore","",1,"velt-single-editor-mode-panel","follow-dialog"],[3,"componentConfigSignal"]],template:function(t,i){t&1&&S(0,vn,2,6,"ng-container",1)(1,fn,1,1,"ng-template",null,0,At),t&2&&v("ngIf",i.componentConfigSignal())},dependencies:[B,Dt,V,W,Ht,xe,Ue,Re,Ne,Pe,we],styles:["html[_ngcontent-%COMP%]{--velt-base-rem-unit: 1}*[data-snippyly-element=true][_ngcontent-%COMP%], *[data-velt-element=true][_ngcontent-%COMP%]{font-family:var(--velt-default-font-family)}velt-wireframe[_ngcontent-%COMP%]{display:none!important}body.velt-pin-dragging[_ngcontent-%COMP%] iframe[_ngcontent-%COMP%]{pointer-events:none!important}[_nghost-%COMP%]{--velt-green: var(--velt-light-mode-green);--velt-magenta: var(--velt-light-mode-magenta);--velt-amber: var(--velt-light-mode-amber);--velt-purple: var(--velt-light-mode-purple);--velt-cyan: var(--velt-light-mode-cyan);--velt-orange: var(--velt-light-mode-orange);--velt-black: var(--velt-light-mode-black);--velt-white: var(--velt-light-mode-white);--velt-gray: var(--velt-light-mode-gray);--velt-error: var(--velt-light-mode-error);--velt-error-hover: var(--velt-light-mode-error-hover);--velt-error-foreground: var(--velt-light-mode-error-foreground);--velt-error-light: var(--velt-light-mode-error-light);--velt-error-transparent: var(--velt-light-mode-error-transparent);--velt-warning: var(--velt-light-mode-warning);--velt-warning-hover: var(--velt-light-mode-warning-hover);--velt-warning-foreground: var(--velt-light-mode-warning-foreground);--velt-warning-light: var(--velt-light-mode-warning-light);--velt-warning-transparent: var(--velt-light-mode-warning-transparent);--velt-agent-accent: #4495ff;--velt-agent-accent-transparent: rgba(68, 149, 255, .2);--velt-success: var(--velt-light-mode-success);--velt-success-hover: var(--velt-light-mode-success-hover);--velt-success-foreground: var(--velt-light-mode-success-foreground);--velt-success-light: var(--velt-light-mode-success-light);--velt-success-transparent: var(--velt-light-mode-success-transparent);--velt-accent: var(--velt-light-mode-accent);--velt-accent-text: var(--velt-light-mode-accent-text);--velt-accent-hover: var(--velt-light-mode-accent-hover);--velt-accent-foreground: var(--velt-light-mode-accent-foreground);--velt-accent-light: var(--velt-light-mode-accent-light);--velt-accent-transparent: var(--velt-light-mode-accent-transparent);--velt-text-0: var(--velt-light-mode-text-0);--velt-text-1: var(--velt-light-mode-text-1);--velt-text-2: var(--velt-light-mode-text-2);--velt-text-3: var(--velt-light-mode-text-3);--velt-text-4: var(--velt-light-mode-text-4);--velt-text-5: var(--velt-light-mode-text-5);--velt-text-6: var(--velt-light-mode-text-6);--velt-text-7: var(--velt-light-mode-text-7);--velt-text-8: var(--velt-light-mode-text-8);--velt-text-9: var(--velt-light-mode-text-9);--velt-text-10: var(--velt-light-mode-text-10);--velt-text-11: var(--velt-light-mode-text-11);--velt-text-12: var(--velt-light-mode-text-12);--velt-background-0: var(--velt-light-mode-background-0);--velt-background-1: var(--velt-light-mode-background-1);--velt-background-2: var(--velt-light-mode-background-2);--velt-background-3: var(--velt-light-mode-background-3);--velt-background-4: var(--velt-light-mode-background-4);--velt-background-5: var(--velt-light-mode-background-5);--velt-background-6: var(--velt-light-mode-background-6);--velt-background-7: var(--velt-light-mode-background-7);--velt-background-8: var(--velt-light-mode-background-8);--velt-background-9: var(--velt-light-mode-background-9);--velt-background-10: var(--velt-light-mode-background-10);--velt-border-0: var(--velt-light-mode-border-0);--velt-border-1: var(--velt-light-mode-border-1);--velt-border-2: var(--velt-light-mode-border-2);--velt-border-3: var(--velt-light-mode-border-3);--velt-border-4: var(--velt-light-mode-border-4);--velt-border-5: var(--velt-light-mode-border-5);--velt-border-6: var(--velt-light-mode-border-6);--velt-border-7: var(--velt-light-mode-border-7);--velt-border-8: var(--velt-light-mode-border-8);--velt-border-9: var(--velt-light-mode-border-9);--velt-border-10: var(--velt-light-mode-border-10);--velt-background-transparent: var(--velt-light-mode-background-transparent);--velt-border-transparent: var(--velt-light-mode-border-transparent);--velt-animation-transparent: var(--velt-light-mode-animation-transparent)}[_nghost-%COMP%]:empty{display:none}[dark][_nghost-%COMP%]{--velt-green: var(--velt-dark-mode-green);--velt-magenta: var(--velt-dark-mode-magenta);--velt-amber: var(--velt-dark-mode-amber);--velt-purple: var(--velt-dark-mode-purple);--velt-cyan: var(--velt-dark-mode-cyan);--velt-orange: var(--velt-dark-mode-orange);--velt-black: var(--velt-dark-mode-black);--velt-white: var(--velt-dark-mode-white);--velt-gray: var(--velt-dark-mode-gray);--velt-error: var(--velt-dark-mode-error);--velt-error-hover: var(--velt-dark-mode-error-hover);--velt-error-foreground: var(--velt-dark-mode-error-foreground);--velt-error-light: var(--velt-dark-mode-error-light);--velt-error-transparent: var(--velt-dark-mode-error-transparent);--velt-warning: var(--velt-dark-mode-warning);--velt-warning-hover: var(--velt-dark-mode-warning-hover);--velt-warning-foreground: var(--velt-dark-mode-warning-foreground);--velt-warning-light: var(--velt-dark-mode-warning-light);--velt-warning-transparent: var(--velt-dark-mode-warning-transparent);--velt-agent-accent: #4495ff;--velt-agent-accent-transparent: rgba(68, 149, 255, .2);--velt-success: var(--velt-dark-mode-success);--velt-success-hover: var(--velt-dark-mode-success-hover);--velt-success-foreground: var(--velt-dark-mode-success-foreground);--velt-success-light: var(--velt-dark-mode-success-light);--velt-success-transparent: var(--velt-dark-mode-success-transparent);--velt-accent: var(--velt-dark-mode-accent);--velt-accent-text: var(--velt-dark-mode-accent-text);--velt-accent-hover: var(--velt-dark-mode-accent-hover);--velt-accent-foreground: var(--velt-dark-mode-accent-foreground);--velt-accent-light: var(--velt-dark-mode-accent-light);--velt-accent-transparent: var(--velt-dark-mode-accent-transparent);--velt-text-0: var(--velt-dark-mode-text-0);--velt-text-1: var(--velt-dark-mode-text-1);--velt-text-2: var(--velt-dark-mode-text-2);--velt-text-3: var(--velt-dark-mode-text-3);--velt-text-4: var(--velt-dark-mode-text-4);--velt-text-5: var(--velt-dark-mode-text-5);--velt-text-6: var(--velt-dark-mode-text-6);--velt-text-7: var(--velt-dark-mode-text-7);--velt-text-8: var(--velt-dark-mode-text-8);--velt-text-9: var(--velt-dark-mode-text-9);--velt-text-10: var(--velt-dark-mode-text-10);--velt-text-11: var(--velt-dark-mode-text-11);--velt-text-12: var(--velt-dark-mode-text-12);--velt-background-0: var(--velt-dark-mode-background-0);--velt-background-1: var(--velt-dark-mode-background-1);--velt-background-2: var(--velt-dark-mode-background-2);--velt-background-3: var(--velt-dark-mode-background-3);--velt-background-4: var(--velt-dark-mode-background-4);--velt-background-5: var(--velt-dark-mode-background-5);--velt-background-6: var(--velt-dark-mode-background-6);--velt-background-7: var(--velt-dark-mode-background-7);--velt-background-8: var(--velt-dark-mode-background-8);--velt-background-9: var(--velt-dark-mode-background-9);--velt-background-10: var(--velt-dark-mode-background-10);--velt-border-0: var(--velt-dark-mode-border-0);--velt-border-1: var(--velt-dark-mode-border-1);--velt-border-2: var(--velt-dark-mode-border-2);--velt-border-3: var(--velt-dark-mode-border-3);--velt-border-4: var(--velt-dark-mode-border-4);--velt-border-5: var(--velt-dark-mode-border-5);--velt-border-6: var(--velt-dark-mode-border-6);--velt-border-7: var(--velt-dark-mode-border-7);--velt-border-8: var(--velt-dark-mode-border-8);--velt-border-9: var(--velt-dark-mode-border-9);--velt-border-10: var(--velt-dark-mode-border-10);--velt-background-transparent: var(--velt-dark-mode-background-transparent);--velt-border-transparent: var(--velt-dark-mode-border-transparent);--velt-animation-transparent: var(--velt-dark-mode-animation-transparent)}.velt-single-editor-mode-panel[_ngcontent-%COMP%]{font-size:var(--velt-font-size-xs);display:flex;justify-content:center;align-items:center;gap:var(--velt-spacing-sm);width:fit-content;padding:var(--velt-spacing-sm) var(--velt-spacing-md);background-color:var(--velt-background-0);color:var(--velt-text-0);border-radius:var(--velt-border-radius-full);box-shadow:0 8px 16px -8px #0f0f0f1a;border:1px solid var(--velt-border-4)}.velt-single-editor-mode-panel-container.velt-single-editor-mode-panel-container-no-pointer[_ngcontent-%COMP%]{pointer-events:none}"],changeDetection:0});let n=r;return n})();function bn(n,r){if(n&1&&(b(0),R(1,"div",1),Ve(2,"velt-single-editor-mode-panel",2),N(),_()),n&2){let o=g(2);h(2),v("variant",o.variant)}}function _n(n,r){if(n&1&&(b(0),S(1,bn,3,1,"ng-container",0),_()),n&2){let o=r.ngIf;h(),v("ngIf",o.singleEditorMode&&o.defaultSingleEditorUIEnabled)}}var gt=(()=>{let r=class r extends it{constructor(e,t,i,s,l,u){super(e,t,void 0,void 0,void 0,i,s),this.elementRef=e,this.themeService=t,this.dynamicDataService=i,this.loggingService=s,this.liveStateService=l,this.domService=u,this.subscriptions=[],this.componentConfigSignal=We({singleEditorMode:!1,defaultSingleEditorUIEnabled:!1,variant:this.variant}),this.componentId="velt-live-state-sync-overlay";try{this.subscriptions.push(this.liveStateService.getSingleEditorMode$().subscribe(d=>{this.componentConfigSignal.update(a=>A(f({},a),{singleEditorMode:d}))})),this.subscriptions.push(this.liveStateService.getDefaultSingleEditorUIEnabled$().subscribe(d=>{this.componentConfigSignal.update(a=>A(f({},a),{defaultSingleEditorUIEnabled:d}))}))}catch(d){this.loggingService.catch("Error in LiveStateSyncOverlayComponent constructor: ",d)}}ngOnInit(){try{super.ngOnInit(),this.setupA11yAttributes()}catch(e){this.loggingService.catch("Error in LiveStateSyncOverlayComponent ngOnInit: ",e)}}ngAfterViewInit(){try{this.subscriptions.push(this.domService.subscribeInjectCustomCss(this.elementRef))}catch(e){this.loggingService.catch("Error in LiveStateSyncOverlayComponent ngAfterViewInit: ",e)}}ngOnDestroy(){try{super.ngOnDestroy(),this.subscriptions.forEach(e=>e.unsubscribe())}catch(e){this.loggingService.catch("Error in LiveStateSyncOverlayComponent ngOnDestroy: ",e)}}setupA11yAttributes(){try{let e=this.elementRef.nativeElement;e.setAttribute("role","dialog"),e.setAttribute("aria-labelledby",this.componentId),e.setAttribute("aria-modal","true")}catch(e){this.loggingService.catch("Error in LiveStateSyncOverlayComponent setupA11yAttributes: ",e)}}};r.\u0275fac=function(t){return new(t||r)(E(F),E(tt),E(U),E(c),E(T),E(De))},r.\u0275cmp=q({type:r,selectors:[["snippyly-live-state-sync-overlay"]],inputs:{variant:"variant"},standalone:!1,features:[He([U]),$],decls:1,vars:1,consts:[[4,"ngIf"],["data-velt-ignore","",1,"velt-live-state-sync-overlay-container","live-state-sync-overlay-container"],[3,"variant"]],template:function(t,i){t&1&&S(0,_n,2,1,"ng-container",0),t&2&&v("ngIf",i.componentConfigSignal())},dependencies:[B,ye],styles:[`html{--velt-base-rem-unit: 1}*[data-snippyly-element=true],*[data-velt-element=true]{font-family:var(--velt-default-font-family)}velt-wireframe{display:none!important}body.velt-pin-dragging iframe{pointer-events:none!important}.velt-live-state-sync-overlay-container{position:fixed;bottom:calc((2rem + 0px) * var(--velt-base-rem-unit));left:50%;transform:translate(-50%);background-color:transparent;z-index:var(--velt-live-state-sync-overlay-z-index);display:flex;justify-content:center;align-items:flex-end}
2
2
  `],encapsulation:3,changeDetection:0});let n=r;return n})();var rt=class extends Kt{constructor(r){super(r),this.getService(c).log("%c[WB] Creating CLASS: LiveStateElement","color: blue;"),this.getLiveStateData$=this._getLiveStateData,this.getLiveStateData=this._getLiveStateData,this.fetchLiveStateData=this._fetchLiveStateData,this.setLiveStateData=this._setLiveStateData,this.enableSingleEditorMode=this._enableSingleEditorMode,this.disableSingleEditorMode=this._disableSingleEditorMode,this.isUserEditor$=this._isUserEditor,this.isUserEditor=this._isUserEditor,this.getEditor=this._getEditor,this.setUserAsEditor=this._setUserAsEditor,this.resetUserAccess=this._resetUserAccess,this.singleEditorModeContainerIds=this._singleEditorModeContainerIds,this.enableAutoSyncState=this._enableAutoSyncState,this.disableAutoSyncState=this._disableAutoSyncState,this.requestEditorAccess=this._requestEditorAccess,this.isEditorAccessRequested=this._isEditorAccessRequested,this.acceptEditorAccessRequest=this._acceptEditorAccessRequest,this.rejectEditorAccessRequest=this._rejectEditorAccessRequest,this.cancelEditorAccessRequest=this._cancelEditorAccessRequest,this.editCurrentTab=this._editCurrentTab,this.setEditorAccessTimeout=this._setEditorAccessTimeout,this.enableEditorAccessTransferOnTimeOut=this._enableEditorAccessTransferOnTimeOut,this.disableEditorAccessTransferOnTimeOut=this._disableEditorAccessTransferOnTimeOut,this.enableDefaultSingleEditorUI=this._enableDefaultSingleEditorUI,this.disableDefaultSingleEditorUI=this._disableDefaultSingleEditorUI,this.getEditorAccessTimer=this._getEditorAccessTimer,this.onServerConnectionStateChange=this._onServerConnectionStateChange,this.updateUserPresence=this._updateUserPresence,this.enableHeartbeat=this._enableHeartbeat,this.disableHeartbeat=this._disableHeartbeat,this.on=this._on}_getLiveStateData(r,o){this.getService(c).log("%c[WB] Calling FUNCTION: getLiveStateData","color: green;");try{return this.trackEvent(m.Events.LiveStateSync.GET_LIVE_STATE_DATA_TRIGGERED),this.getService(T).getLiveStateData$(r,o)}catch(e){return this.getService(c).catch("Error in _getLiveStateData: ",e),p(null)}}_fetchLiveStateData(r){this.getService(c).log("%c[WB] Calling FUNCTION: fetchLiveStateData","color: green;");try{return this.trackEvent(m.Events.LiveStateSync.FETCH_LIVE_STATE_DATA_TRIGGERED,{payload:{request:r}}),this.getService(T).fetchLiveStateData(r)}catch(o){return this.getService(c).catch("Error in _fetchLiveStateData: ",o),Promise.resolve(null)}}_setLiveStateData(r,o,e){this.getService(c).log("%c[WB] Calling FUNCTION: setLiveStateData","color: green;");try{return this.getService(T).setLiveStateData(r,o,e)}catch(t){return this.getService(c).catch("Error in _setLiveStateData: ",t),Promise.resolve()}}_enableSingleEditorMode(r){this.getService(c).log("%c[WB] Calling FUNCTION: enableSingleEditorMode","color: green;");try{this.trackEvent(m.Events.LiveStateSync.ENABLE_SINGLE_EDITOR_MODE_TRIGGERED),this.getService(T).enableSingleEditorMode(r)}catch(o){this.getService(c).catch("Error in _enableSingleEditorMode: ",o)}}_disableSingleEditorMode(){this.getService(c).log("%c[WB] Calling FUNCTION: disableSingleEditorMode","color: green;");try{this.trackEvent(m.Events.LiveStateSync.DISABLE_SINGLE_EDITOR_MODE_TRIGGERED),this.getService(T).disableSingleEditorMode()}catch(r){this.getService(c).catch("Error in _disableSingleEditorMode: ",r)}}_isUserEditor(){this.getService(c).log("%c[WB] Calling FUNCTION: isUserEditor$","color: green;");try{return this.trackEvent(m.Events.LiveStateSync.IS_USER_EDITOR_TRIGGERED),this.getService(T).isUserEditor$()}catch(r){return this.getService(c).catch("Error in _isUserEditor$: ",r),p(null)}}_getEditor(){this.getService(c).log("%c[WB] Calling FUNCTION: getEditor","color: green;");try{return this.trackEvent(m.Events.LiveStateSync.GET_EDITOR_TRIGGERED),this.getService(T).getEditor$()}catch(r){return this.getService(c).catch("Error in _getEditor: ",r),p(null)}}_setUserAsEditor(){this.getService(c).log("%c[WB] Calling FUNCTION: setUserAsEditor","color: green;");try{return this.trackEvent(m.Events.LiveStateSync.SET_USER_AS_EDITOR_TRIGGERED),this.getService(T).setUserAsEditor()}catch(r){return this.getService(c).catch("Error in _setUserAsEditor: ",r),Promise.resolve()}}_resetUserAccess(){this.getService(c).log("%c[WB] Calling FUNCTION: resetUserAccess","color: green;");try{this.trackEvent(m.Events.LiveStateSync.RESET_USER_ACCESS_TRIGGERED),this.getService(T).removeEditorAccess({metadata:{from:"resetUserAccess-liveStateSyncElement",reason:"Client called"}})}catch(r){this.getService(c).catch("Error in _resetUserAccess: ",r)}}_singleEditorModeContainerIds(r){this.getService(c).log("%c[WB] Calling FUNCTION: singleEditorModeContainerIds","color: green;");try{this.trackEvent(m.Events.LiveStateSync.SINGLE_EDITOR_MODE_CONTAINER_IDS_TRIGGERED),this.getService(T).setSingleEditorModeContainerIds(r)}catch(o){this.getService(c).catch("Error in _singleEditorModeContainerIds: ",o)}}_enableAutoSyncState(){this.getService(c).log("%c[WB] Calling FUNCTION: enableAutoSyncState","color: green;");try{this.trackEvent(m.Events.LiveStateSync.ENABLE_AUTO_SYNC_STATE_TRIGGERED),this.getService(T).enableAutoSyncState()}catch(r){this.getService(c).catch("Error in _enableAutoSyncState: ",r)}}_disableAutoSyncState(){this.getService(c).log("%c[WB] Calling FUNCTION: disableAutoSyncState","color: green;");try{this.trackEvent(m.Events.LiveStateSync.DISABLE_AUTO_SYNC_STATE_TRIGGERED),this.getService(T).disableAutoSyncState()}catch(r){this.getService(c).catch("Error in _disableAutoSyncState: ",r)}}_requestEditorAccess(){this.getService(c).log("%c[WB] Calling FUNCTION: requestEditorAccess","color: green;");try{return this.trackEvent(m.Events.LiveStateSync.REQUEST_EDITOR_ACCESS_TRIGGERED),this.getService(T).requestEditorAccess()}catch(r){return this.getService(c).catch("Error in _requestEditorAccess: ",r),p(null)}}_isEditorAccessRequested(){this.getService(c).log("%c[WB] Calling FUNCTION: isEditorAccessRequested","color: green;");try{return this.trackEvent(m.Events.LiveStateSync.IS_EDITOR_ACCESS_REQUESTED_TRIGGERED),this.getService(T).isEditorAccessRequested$()}catch(r){return this.getService(c).catch("Error in _isEditorAccessRequested: ",r),p(null)}}_acceptEditorAccessRequest(){this.getService(c).log("%c[WB] Calling FUNCTION: acceptEditorAccessRequest","color: green;");try{this.trackEvent(m.Events.LiveStateSync.ACCEPT_EDITOR_ACCESS_REQUEST_TRIGGERED),this.getService(T).acceptEditorAccessRequest()}catch(r){this.getService(c).catch("Error in _acceptEditorAccessRequest: ",r)}}_rejectEditorAccessRequest(){this.getService(c).log("%c[WB] Calling FUNCTION: rejectEditorAccessRequest","color: green;");try{this.trackEvent(m.Events.LiveStateSync.REJECT_EDITOR_ACCESS_REQUEST_TRIGGERED),this.getService(T).rejectEditorAccessRequest()}catch(r){this.getService(c).catch("Error in _rejectEditorAccessRequest: ",r)}}_cancelEditorAccessRequest(){this.getService(c).log("%c[WB] Calling FUNCTION: cancelEditorAccessRequest","color: green;");try{this.trackEvent(m.Events.LiveStateSync.CANCEL_EDITOR_ACCESS_REQUEST_TRIGGERED),this.getService(T).cancelEditorAccessRequest()}catch(r){this.getService(c).catch("Error in _cancelEditorAccessRequest: ",r)}}_editCurrentTab(){this.getService(c).log("%c[WB] Calling FUNCTION: editCurrentTab","color: green;");try{this.trackEvent(m.Events.LiveStateSync.EDIT_CURRENT_TAB_TRIGGERED),this.getService(T).editCurrentTab()}catch(r){this.getService(c).catch("Error in _editCurrentTab: ",r)}}_setEditorAccessTimeout(r){this.getService(c).log("%c[WB] Calling FUNCTION: setEditorAccessTimeout","color: green;");try{this.trackEvent(m.Events.LiveStateSync.SET_EDITOR_ACCESS_TIMEOUT_TRIGGERED),this.getService(T).setEditorAccessTimeout(r)}catch(o){this.getService(c).catch("Error in _setEditorAccessTimeout: ",o)}}_enableEditorAccessTransferOnTimeOut(){this.getService(c).log("%c[WB] Calling FUNCTION: enableEditorAccessTransferOnTimeOut","color: green;");try{this.trackEvent(m.Events.LiveStateSync.ENABLE_EDITOR_ACCESS_TRANSFER_ON_TIMEOUT_TRIGGERED),this.getService(T).enableEditorAccessTransferOnTimeOut()}catch(r){this.getService(c).catch("Error in _enableEditorAccessTransferOnTimeOut: ",r)}}_disableEditorAccessTransferOnTimeOut(){this.getService(c).log("%c[WB] Calling FUNCTION: disableEditorAccessTransferOnTimeOut","color: green;");try{this.trackEvent(m.Events.LiveStateSync.DISABLE_EDITOR_ACCESS_TRANSFER_ON_TIMEOUT_TRIGGERED),this.getService(T).disableEditorAccessTransferOnTimeOut()}catch(r){this.getService(c).catch("Error in _disableEditorAccessTransferOnTimeOut: ",r)}}_enableDefaultSingleEditorUI(){this.getService(c).log("%c[WB] Calling FUNCTION: enableDefaultSingleEditorUI","color: green;");try{this.trackEvent(m.Events.LiveStateSync.ENABLE_DEFAULT_SINGLE_EDITOR_UI_TRIGGERED),this.getService(T).enableDefaultSingleEditorUI()}catch(r){this.getService(c).catch("Error in _enableDefaultSingleEditorUI: ",r)}}_disableDefaultSingleEditorUI(){this.getService(c).log("%c[WB] Calling FUNCTION: disableDefaultSingleEditorUI","color: green;");try{this.trackEvent(m.Events.LiveStateSync.DISABLE_DEFAULT_SINGLE_EDITOR_UI_TRIGGERED),this.getService(T).disableDefaultSingleEditorUI()}catch(r){this.getService(c).catch("Error in _disableDefaultSingleEditorUI: ",r)}}_getEditorAccessTimer(){this.getService(c).log("%c[WB] Calling FUNCTION: getEditorAccessTimer","color: green;");try{return this.trackEvent(m.Events.LiveStateSync.GET_EDITOR_ACCESS_TIMER_TRIGGERED),this.getService(T).getEditorAccessTimer$()}catch(r){return this.getService(c).catch("Error in _getEditorAccessTimer: ",r),p(new Ke)}}_onServerConnectionStateChange(){this.getService(c).log("%c[WB] Calling FUNCTION: onServerConnectionStateChange","color: green;");try{return this.trackEvent(m.Events.LiveStateSync.ON_SERVER_CONNECTION_STATE_CHANGE_TRIGGERED),this.getService(T).onServerConnectionStateChange$()}catch(r){return this.getService(c).catch("Error in _onServerConnectionStateChange: ",r),p(K.PENDING_INIT)}}_updateUserPresence(r){this.getService(c).log("%c[WB] Calling FUNCTION: updateUserPresence","color: green;");try{this.trackEvent(m.Events.LiveStateSync.UPDATE_USER_PRESENCE_TRIGGERED,{payload:{userPresence:r}}),this.getService(T).updateExternalUserPresence(r)}catch(o){this.getService(c).catch("Error in _updateUserPresence: ",o)}}_enableHeartbeat(){this.getService(c).log("%c[WB] Calling FUNCTION: enableHeartbeat","color: green;");try{this.trackEvent(m.Events.LiveStateSync.ENABLE_HEARTBEAT_TRIGGERED),this.getService(T).enableHeartbeat()}catch(r){this.getService(c).catch("Error in _enableHeartbeat: ",r)}}_disableHeartbeat(){this.getService(c).log("%c[WB] Calling FUNCTION: disableHeartbeat","color: green;");try{this.trackEvent(m.Events.LiveStateSync.DISABLE_HEARTBEAT_TRIGGERED),this.getService(T).disableHeartbeat()}catch(r){this.getService(c).catch("Error in _disableHeartbeat: ",r)}}_on(r){this.getService(c).log("%c[WB] Calling FUNCTION: on","color: green;");try{return this.getService(nt).onAction(r)}catch(o){return this.getService(c).catch("Error in _on: ",o),p(null)}}};var ci=n=>({componentConfigSignal:n}),In=(n,r)=>({condition:n,data:r}),yn=(n,r,o,e,t)=>({template:n,context:r,componentName:"velt-single-editor-mode-panel-accept-request-wireframe",variant:o,setIfCondition:e,componentElementRef:t});function Tn(n,r){n&1&&(b(0),X(1),J(2,"translate"),_()),n&2&&(h(),Z(" ",z(2,1,"Accept Request")," "))}function An(n,r){if(n&1){let o=ge();R(0,"button",3),ue("click",function(){le(o);let t=g(2).ngIf;return de(t.acceptEditorAccessRequest())}),S(1,Tn,3,3,"ng-container",4),N()}if(n&2){let o=g(2).ngIf,e=g();h(),v("veltDynamicTemplate",G(3,yn,e.template,x(1,ci,e.componentConfigSignal),o==null?null:o.variant,e.setIfCondition.bind(e),e.elementRef))}}function Dn(n,r){if(n&1&&(b(0),S(1,An,2,9,"button",2),_()),n&2){let o=g().ngIf;h(),v("ngIf",o.type==="editor"&&o.requestEditorAccessCountdown)}}function On(n,r){if(n&1&&(b(0),S(1,Dn,2,1,"ng-container",1),_()),n&2){let o=g();h(),v("veltIf",j(3,In,o.conditionSignal(),x(1,ci,o.componentConfigSignal)))}}var ut=(()=>{let r=class r extends te{constructor(e,t,i){super(e,t,i),this.elementRef=e,this.dynamicDataService=t,this.loggingService=i,this.componentId="velt-single-editor-mode-panel-accept-request";try{super.initializeComponentConfigSignal(new H)}catch(s){this.loggingService.catch("Error in SingleEditorModePanelAcceptRequestComponent constructor:",s)}}ngOnInit(){try{super.ngOnInit(),this.setupA11yAttributes()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelAcceptRequestComponent ngOnInit: ",e)}}ngOnDestroy(){try{super.ngOnDestroy()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelAcceptRequestComponent ngOnDestroy: ",e)}}setupA11yAttributes(){try{this.elementRef.nativeElement.setAttribute("data-testid",this.componentId+"-container")}catch(e){this.loggingService.catch("Error in SingleEditorModePanelAcceptRequestComponent setupA11yAttributes:",e)}}};r.\u0275fac=function(t){return new(t||r)(E(F),E(U),E(c))},r.\u0275cmp=q({type:r,selectors:[["velt-single-editor-mode-panel-accept-request"]],standalone:!1,features:[$],decls:1,vars:1,consts:[[4,"ngIf"],[4,"veltIf"],["class","velt-single-editor-mode-panel-btn follow-btn","data-velt-ignore","",3,"click",4,"ngIf"],["data-velt-ignore","",1,"velt-single-editor-mode-panel-btn","follow-btn",3,"click"],[4,"veltDynamicTemplate"]],template:function(t,i){t&1&&S(0,On,2,6,"ng-container",0),t&2&&v("ngIf",i.componentConfigSignal())},dependencies:[B,V,W,re],styles:["html[_ngcontent-%COMP%]{--velt-base-rem-unit: 1}*[data-snippyly-element=true][_ngcontent-%COMP%], *[data-velt-element=true][_ngcontent-%COMP%]{font-family:var(--velt-default-font-family)}velt-wireframe[_ngcontent-%COMP%]{display:none!important}body.velt-pin-dragging[_ngcontent-%COMP%] iframe[_ngcontent-%COMP%]{pointer-events:none!important}[_nghost-%COMP%]:empty{display:none}.velt-single-editor-mode-panel-btn[_ngcontent-%COMP%]{background-color:var(--velt-background-3);color:var(--velt-text-0);padding:var(--velt-spacing-sm) var(--velt-spacing-md);border-radius:var(--velt-border-radius-full);display:inline-flex;justify-content:center;align-items:center;border:none;font-weight:600;font-size:var(--velt-font-size-sm);cursor:pointer;pointer-events:all}.velt-single-editor-mode-panel-btn[_ngcontent-%COMP%]:hover{transition:background-color .5s;background-color:var(--velt-background-5)}"],changeDetection:0});let n=r;return n})();var li=n=>({componentConfigSignal:n}),Mn=(n,r)=>({condition:n,data:r}),Ln=(n,r,o,e,t)=>({template:n,context:r,componentName:"velt-single-editor-mode-panel-cancel-request-wireframe",variant:o,setIfCondition:e,componentElementRef:t});function xn(n,r){n&1&&(b(0),X(1),J(2,"translate"),_()),n&2&&(h(),Z(" ",z(2,1,"Cancel Request")," "))}function Un(n,r){if(n&1){let o=ge();R(0,"button",3),ue("click",function(){le(o);let t=g(2).ngIf;return de(t.cancelEditorAccessRequest())}),S(1,xn,3,3,"ng-container",4),N()}if(n&2){let o=g(2).ngIf,e=g();h(),v("veltDynamicTemplate",G(3,Ln,e.template,x(1,li,e.componentConfigSignal),o==null?null:o.variant,e.setIfCondition.bind(e),e.elementRef))}}function Rn(n,r){if(n&1&&(b(0),S(1,Un,2,9,"button",2),_()),n&2){let o=g().ngIf;h(),v("ngIf",o.type!=="editor"&&o.editAccessRequested)}}function Nn(n,r){if(n&1&&(b(0),S(1,Rn,2,1,"ng-container",1),_()),n&2){let o=g();h(),v("veltIf",j(3,Mn,o.conditionSignal(),x(1,li,o.componentConfigSignal)))}}var vt=(()=>{let r=class r extends te{constructor(e,t,i){super(e,t,i),this.elementRef=e,this.dynamicDataService=t,this.loggingService=i,this.componentId="velt-single-editor-mode-panel-cancel-request";try{super.initializeComponentConfigSignal(new H)}catch(s){this.loggingService.catch("Error in SingleEditorModePanelCancelRequestComponent constructor:",s)}}ngOnInit(){try{super.ngOnInit(),this.setupA11yAttributes()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelCancelRequestComponent ngOnInit: ",e)}}ngOnDestroy(){try{super.ngOnDestroy()}catch(e){this.loggingService.catch("Error in SingleEditorModePanelCancelRequestComponent ngOnDestroy: ",e)}}setupA11yAttributes(){try{this.elementRef.nativeElement.setAttribute("data-testid",this.componentId+"-container")}catch(e){this.loggingService.catch("Error in SingleEditorModePanelCancelRequestComponent setupA11yAttributes:",e)}}};r.\u0275fac=function(t){return new(t||r)(E(F),E(U),E(c))},r.\u0275cmp=q({type:r,selectors:[["velt-single-editor-mode-panel-cancel-request"]],standalone:!1,features:[$],decls:1,vars:1,consts:[[4,"ngIf"],[4,"veltIf"],["class","velt-single-editor-mode-panel-btn follow-btn","data-velt-ignore","",3,"click",4,"ngIf"],["data-velt-ignore","",1,"velt-single-editor-mode-panel-btn","follow-btn",3,"click"],[4,"veltDynamicTemplate"]],template:function(t,i){t&1&&S(0,Nn,2,6,"ng-container",0),t&2&&v("ngIf",i.componentConfigSignal())},dependencies:[B,V,W,re],styles:["html[_ngcontent-%COMP%]{--velt-base-rem-unit: 1}*[data-snippyly-element=true][_ngcontent-%COMP%], *[data-velt-element=true][_ngcontent-%COMP%]{font-family:var(--velt-default-font-family)}velt-wireframe[_ngcontent-%COMP%]{display:none!important}body.velt-pin-dragging[_ngcontent-%COMP%] iframe[_ngcontent-%COMP%]{pointer-events:none!important}[_nghost-%COMP%]:empty{display:none}.velt-single-editor-mode-panel-btn[_ngcontent-%COMP%]{background-color:var(--velt-background-3);color:var(--velt-text-0);padding:var(--velt-spacing-sm) var(--velt-spacing-md);border-radius:var(--velt-border-radius-full);display:inline-flex;justify-content:center;align-items:center;border:none;font-weight:600;font-size:var(--velt-font-size-sm);cursor:pointer;pointer-events:all}.velt-single-editor-mode-panel-btn[_ngcontent-%COMP%]:hover{transition:background-color .5s;background-color:var(--velt-background-5)}"],changeDetection:0});let n=r;return n})();var di=(()=>{let r=class r{};r.\u0275fac=function(t){return new(t||r)},r.\u0275mod=It({type:r}),r.\u0275inj=Ct({imports:[Ot,Jt]});let n=r;return n})();var Pn={"velt-single-editor-mode-panel-wireframe":ye,"velt-single-editor-mode-panel-request-access-wireframe":we,"velt-single-editor-mode-panel-reject-request-wireframe":Pe,"velt-single-editor-mode-panel-viewer-text-wireframe":Ne,"velt-single-editor-mode-panel-editor-text-wireframe":Re,"velt-single-editor-mode-panel-edit-here-wireframe":Ue,"velt-single-editor-mode-panel-countdown-wireframe":xe,"velt-single-editor-mode-panel-cancel-request-wireframe":vt,"velt-single-editor-mode-panel-accept-request-wireframe":ut};Object.assign(Vt,Pn);function wn(n){n.get(c).log("%c[WB] Loading LiveStateSync feature chunk","color: blue;"),n.get(Ye).set(kt,n.get(T));let t=_t(di,n).injector;return gi(t,"snippyly-live-state-sync-overlay",gt),gi(t,ee.TAGS.VELT_SINGLE_EDITOR_MODE_PANEL,ye),new rt(n)}function gi(n,r,o){if(customElements.get(r))return;let e=Mt(o,{injector:n});customElements.define(r,e)}export{wn as default};