@thebase/ui
Version:
CDN-installable Owl and Bootstrap 5 UI component library.
2 lines (1 loc) • 2.15 kB
JavaScript
import{a as b}from"./chunk-K2ROPYIW.js";import{Ga as L,T as p,U as c,bb as m,db as w,h,pb as y,ya as f}from"./chunk-XNCXGIZE.js";var k=class{constructor(){this.beforeMountedListeners=[],this.mountedListeners=[],this.updatedListeners=[],this.selectionUpdatedListeners=[],this.markdownUpdatedListeners=[],this.blurListeners=[],this.focusListeners=[],this.destroyListeners=[],this.beforeMount=e=>(this.beforeMountedListeners.push(e),this),this.mounted=e=>(this.mountedListeners.push(e),this),this.updated=e=>(this.updatedListeners.push(e),this)}get listeners(){return{beforeMount:this.beforeMountedListeners,mounted:this.mountedListeners,updated:this.updatedListeners,markdownUpdated:this.markdownUpdatedListeners,blur:this.blurListeners,focus:this.focusListeners,destroy:this.destroyListeners,selectionUpdated:this.selectionUpdatedListeners}}markdownUpdated(e){return this.markdownUpdatedListeners.push(e),this}blur(e){return this.blurListeners.push(e),this}focus(e){return this.focusListeners.push(e),this}destroy(e){return this.destroyListeners.push(e),this}selectionUpdated(e){return this.selectionUpdatedListeners.push(e),this}},g=h(new k,"listener"),E=new c("MILKDOWN_LISTENER"),M=e=>(e.inject(g,new k),async()=>{await e.wait(L);let{listeners:r}=e.get(g);r.beforeMount.forEach(t=>t(e)),await e.wait(m);let u=e.get(w),n=null,d=null,i=null,o=null,l=b(()=>{if(!o)return;let{doc:t}=o;if(r.updated.length>0&&n&&!n.eq(t)&&r.updated.forEach(s=>{s(e,t,n)}),r.markdownUpdated.length>0&&n&&!n.eq(t)){let s=u(t);r.markdownUpdated.forEach(a=>{a(e,s,d)}),d=s}n=t,o=null},200),U=new p({key:E,view:()=>({destroy:()=>{l.cancel(),r.destroy.forEach(t=>t(e))}}),props:{handleDOMEvents:{focus:()=>(r.focus.forEach(t=>t(e)),!1),blur:()=>(r.blur.forEach(t=>t(e)),!1)}},state:{init:(t,s)=>{n=s.doc,d=u(s.doc)},apply:t=>{let s=t.selection;(!i&&s||i&&!s.eq(i))&&(r.selectionUpdated.forEach(a=>{a(e,s,i)}),i=s),!(!(t.docChanged||t.storedMarksSet)||t.getMeta("addToHistory")===!1)&&(o=t,l())}}});e.update(f,t=>t.concat(U)),await e.wait(y),r.mounted.forEach(t=>t(e))});M.meta={package:"@milkdown/plugin-listener",displayName:"Listener"};export{k as a,g as b,E as c,M as d};