@thebase/ui
Version:
CDN-installable Owl and Bootstrap 5 UI component library.
2 lines (1 loc) • 1.24 kB
JavaScript
import{I as f,J as m,K as b,R as l,S as y,T as w,b as d,c as u,p as a,pa as U,r as o,ra as S,ta as x,x as c,z as h}from"./chunk-VJBGANAS.js";var V=new Map,i=class{constructor(t){this.room=t,this.onmessage=null,this._onChange=s=>s.key===t&&this.onmessage!==null&&this.onmessage({data:w(s.newValue||"")}),m(this._onChange)}postMessage(t){f.setItem(this.room,y(l(t)))}close(){b(this._onChange)}},k=typeof BroadcastChannel>"u"?i:BroadcastChannel,p=e=>d(V,e,()=>{let t=u(),s=new k(e);return s.onmessage=n=>t.forEach(r=>r(n.data,"broadcastchannel")),{bc:s,subs:t}}),F=(e,t)=>(p(e).subs.add(t),t),T=(e,t)=>{let s=p(e),n=s.subs.delete(t);return n&&s.subs.size===0&&(s.bc.close(),V.delete(e)),n},q=(e,t,s=null)=>{let n=p(e);n.bc.postMessage(t),n.subs.forEach(r=>r(t,s))};var C=0,A=1,Y=2,N=(e,t)=>{a(e,C);let s=x(t);o(e,s)},j=(e,t,s)=>{a(e,A),o(e,S(t,s))},M=(e,t,s)=>j(t,s,c(e)),B=(e,t,s,n)=>{try{U(t,c(e),s)}catch(r){n?.(r),console.error("Caught error while handling a Yjs update",r)}},Q=(e,t)=>{a(e,Y),o(e,t)},E=B,R=(e,t,s,n,r)=>{let g=h(e);switch(g){case C:M(e,t,s);break;case A:B(e,s,n,r);break;case Y:E(e,s,n,r);break;default:throw new Error("Unknown message type")}return g};export{F as a,T as b,q as c,C as d,A as e,N as f,j as g,Q as h,R as i};