UNPKG

n8n-editor-ui

Version:

Workflow Editor UI for n8n

2 lines 5.01 kB
(function(){try{var e=typeof window<`u`?window:typeof global<`u`?global:typeof globalThis<`u`?globalThis:typeof self<`u`?self:{};e.SENTRY_RELEASE={id:`n8n@2.13.4`}}catch{}})();try{(function(){var e=typeof window<`u`?window:typeof global<`u`?global:typeof globalThis<`u`?globalThis:typeof self<`u`?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]=`bb7cc1c8-6a16-434e-ac4b-41b9fd54b7f0`,e._sentryDebugIdIdentifier=`sentry-dbid-bb7cc1c8-6a16-434e-ac4b-41b9fd54b7f0`)})()}catch{}import{Ft as e,S as t}from"./vue.runtime.esm-bundler-D9KLAxvJ.js";import{bt as n}from"./_MapCache-CUJwh2qp.js";import{gt as r}from"./src-wni2AGA3.js";import{Gr as i,Or as a,cn as o,ka as s,r as c,s as l,sl as u,t as d}from"./users.store-BHWXXawf.js";import{Cl as f,ms as p}from"./constants-CIP7tKq1.js";import{j as m,r as h}from"./_baseOrderBy-CaKruttV.js";import{t as g}from"./pushConnection.store-L5aofOKN.js";function _({route:r}){let i=c(),o=a(),s=n(),l=e(null),u=t(()=>r.name===p.DEMO),d=[];function f(e){if(!(u.value||window.preventNodeViewBeforeUnload)){if(d.forEach(e=>e()),i.stateIsDirty)return e.returnValue=!0,!0;o.startLoading(s.baseText(`nodeView.redirecting`))}}function m(e){d.push(e)}function h(){window.addEventListener(`beforeunload`,f)}function g(){l.value&&clearTimeout(l.value),window.removeEventListener(`beforeunload`,f)}return{onBeforeUnload:f,addBeforeUnloadEventBindings:h,removeBeforeUnloadEventBindings:g,addBeforeUnloadHandler:m}}var ee=5*f.MINUTE,te=30*f.SECOND,ne=20*f.SECOND,v=5*f.SECOND,y=20*f.SECOND;const b=m(u.COLLABORATION,()=>{let n=g(),a=l(),u=i(),p=d(),m=c(),b=h(),x=o(),{addBeforeUnloadEventBindings:S,removeBeforeUnloadEventBindings:C,addBeforeUnloadHandler:re}=_({route:r()}),w=e(null),T=e([]),E=e(null),D=e(Date.now()),O=e(null),k=e(null),A=e(null),j=e(null),M=e(null),N=e(null),P=null,F=t(()=>E.value?.clientId===b.pushRef),I=t(()=>E.value?.userId===p.currentUserId),L=t(()=>T.value.find(e=>e.user.id===E.value?.userId)??null),R=t(()=>E.value!==null),z=t(()=>R.value&&!F.value);async function B(){try{let{workflowId:e}=a;return a.isWorkflowSaved[e]?await s(b.restApiContext,e):null}catch{return null}}function V(){N.value&&n.send({type:`workflowOpened`,workflowId:N.value})}function H(){N.value&&(n.send({type:`workflowClosed`,workflowId:N.value}),T.value=T.value.filter(({user:e})=>e.id!==p.currentUserId))}let U=()=>{k.value!==null&&(clearInterval(k.value),k.value=null)},W=()=>{U(),k.value=window.setInterval(V,ee)},G=()=>{A.value!==null&&(clearInterval(A.value),A.value=null)},K=()=>{if(!F.value||!N.value){G();return}n.send({type:`writeAccessHeartbeat`,workflowId:N.value})},q=()=>{G(),A.value=window.setInterval(K,te)},J=()=>{j.value!==null&&(clearInterval(j.value),j.value=null)},Y=async()=>{if(!z.value){J();return}!await B()&&E.value&&(E.value=null,J())},X=()=>{J(),j.value=window.setInterval(Y,ne)};re(()=>{H(),m.stateIsDirty&&(w.value=setTimeout(()=>V,5*f.SECOND))});function Z(){D.value=Date.now()}function ie(){if(F.value)return!0;if(!N.value)return!1;try{n.send({type:`writeAccessRequested`,workflowId:N.value})}catch{return!1}return!0}function ae(){if(!N.value)return!1;try{n.send({type:`writeAccessRequested`,workflowId:N.value,force:!0})}catch{return!1}return!0}function Q(){if(E.value=null,G(),!N.value)return!0;try{return n.send({type:`writeAccessReleaseRequested`,workflowId:N.value}),!0}catch{return!1}}function oe(){F.value&&(x.streaming||Date.now()-D.value>=y&&Q())}function $(){O.value!==null&&(clearInterval(O.value),O.value=null)}function se(){$(),O.value=window.setInterval(oe,v)}function ce(e){P=e}async function le(){if(!(F.value||!N.value))try{let e=await u.fetchWorkflow(N.value);return P&&P(e),!0}catch(e){return console.error(`[Collaboration] Error in handleWorkflowUpdate:`,e),!1}}function ue(){E.value&&(T.value.some(e=>e.user.id===E.value?.userId)||(E.value=null))}async function de(){if(M.value)return;N.value=a.workflowId;let e=await B();e&&(E.value=e,F.value?q():X()),M.value=n.addEventListener(e=>{if(e.type===`collaboratorsChanged`&&e.data.workflowId===N.value){T.value=e.data.collaborators,ue();return}if(e.type===`writeAccessAcquired`&&e.data.workflowId===N.value){E.value={clientId:e.data.clientId,userId:e.data.userId},F.value?(Z(),q(),J()):X();return}if(e.type===`writeAccessReleased`&&e.data.workflowId===N.value){E.value=null,G(),J();return}if(e.type===`workflowUpdated`&&e.data.workflowId===N.value){le();return}}),S(),V(),W(),se()}function fe(){typeof M.value==`function`&&(M.value(),M.value=null),H(),U(),G(),J(),$(),F.value&&Q(),n.clearQueue(),C(),w.value&&clearTimeout(w.value),N.value=null,E.value=null,T.value=[]}return{collaborators:T,currentWriter:L,isCurrentTabWriter:F,isCurrentUserWriter:I,isAnyoneWriting:R,shouldBeReadOnly:z,requestWriteAccess:ie,requestWriteAccessForce:ae,releaseWriteAccess:Q,recordActivity:Z,initialize:de,terminate:fe,startHeartbeat:W,stopHeartbeat:U,setRefreshCanvasCallback:ce}});export{_ as n,b as t}; //# sourceMappingURL=collaboration.store-BcnGWDqh.js.map