UNPKG

@thebase/ui

Version:

CDN-installable Owl and Bootstrap 5 UI component library.

2 lines (1 loc) • 2.51 kB
import{A,F as g,O as U,e as V,f as y,l as k,n as v,p as u,q as L,w as x,z as f}from"./chunk-VJBGANAS.js";var S=3e4,M=class extends V{constructor(o){super(),this.doc=o,this.clientID=o.clientID,this.states=new Map,this.meta=new Map,this._checkInterval=setInterval(()=>{let n=g();this.getLocalState()!==null&&S/2<=n-this.meta.get(this.clientID).lastUpdated&&this.setLocalState(this.getLocalState());let i=[];this.meta.forEach((s,t)=>{t!==this.clientID&&S<=n-s.lastUpdated&&this.states.has(t)&&i.push(t)}),i.length>0&&T(this,i,"timeout")},y(S/10)),o.on("destroy",()=>{this.destroy()}),this.setLocalState({})}destroy(){this.emit("destroy",[this]),this.setLocalState(null),super.destroy(),clearInterval(this._checkInterval)}getLocalState(){return this.states.get(this.clientID)||null}setLocalState(o){let n=this.clientID,i=this.meta.get(n),s=i===void 0?0:i.clock+1,t=this.states.get(n);o===null?this.states.delete(n):this.states.set(n,o),this.meta.set(n,{clock:s,lastUpdated:g()});let c=[],l=[],d=[],h=[];o===null?h.push(n):t==null?o!=null&&c.push(n):(l.push(n),U(t,o)||d.push(n)),(c.length>0||d.length>0||h.length>0)&&this.emit("change",[{added:c,updated:d,removed:h},"local"]),this.emit("update",[{added:c,updated:l,removed:h},"local"])}setLocalStateField(o,n){let i=this.getLocalState();i!==null&&this.setLocalState({...i,[o]:n})}getStates(){return this.states}},T=(e,o,n)=>{let i=[];for(let s=0;s<o.length;s++){let t=o[s];if(e.states.has(t)){if(e.states.delete(t),t===e.clientID){let c=e.meta.get(t);e.meta.set(t,{clock:c.clock+1,lastUpdated:g()})}i.push(t)}}i.length>0&&(e.emit("change",[{added:[],updated:[],removed:i},n]),e.emit("update",[{added:[],updated:[],removed:i},n]))},C=(e,o,n=e.states)=>{let i=o.length,s=k();u(s,i);for(let t=0;t<i;t++){let c=o[t],l=n.get(c)||null,d=e.meta.get(c).clock;u(s,c),u(s,d),L(s,JSON.stringify(l))}return v(s)};var F=(e,o,n)=>{let i=x(o),s=g(),t=[],c=[],l=[],d=[],h=f(i);for(let D=0;D<h;D++){let a=f(i),p=f(i),r=JSON.parse(A(i)),m=e.meta.get(a),O=e.states.get(a),I=m===void 0?0:m.clock;(I<p||I===p&&r===null&&e.states.has(a))&&(r===null?a===e.clientID&&e.getLocalState()!=null?p++:e.states.delete(a):e.states.set(a,r),e.meta.set(a,{clock:p,lastUpdated:s}),m===void 0&&r!==null?t.push(a):m!==void 0&&r===null?d.push(a):r!==null&&(U(r,O)||l.push(a),c.push(a)))}(t.length>0||l.length>0||d.length>0)&&e.emit("change",[{added:t,updated:l,removed:d},n]),(t.length>0||c.length>0||d.length>0)&&e.emit("update",[{added:t,updated:c,removed:d},n])};export{M as a,T as b,C as c,F as d};