jodit-pro
Version:
PRO Version of Jodit Editor
2 lines (1 loc) • 1.87 kB
JavaScript
var w=Object.defineProperty;var b=(g,t)=>w(g,"name",{value:t,configurable:!0});import{Dom as y}from"jodit/esm/core/dom/dom.js";const r=new WeakMap,h=class h{static install(t,e,o={}){this.remove(t);const{panelHeight:d=250,containerClassName:l,toolbarSelector:i=".jodit-toolbar__box",gap:c=16}=o,s=t.j.c.div("jodit-flight-position");l&&s.classList.add(l),s.style.setProperty("--flight-panel-height",`${d}px`),s.appendChild(t.container),document.body.appendChild(s);const a={toolbarSelector:i,gap:c},n=b(()=>{this.updatePosition(s,e,a)},"onScroll"),p=new ResizeObserver(n);p.observe(e),window.addEventListener("scroll",n,{passive:!0}),window.addEventListener("resize",n,{passive:!0});const v={container:s,anchor:e,onScroll:n,resizeObserver:p,options:a};r.set(t,v),this.updatePosition(s,e,a)}static updatePosition(t,e,o){const{toolbarSelector:d,gap:l}=o,i=e.getBoundingClientRect(),c=window.innerHeight,s=t.offsetHeight||250;t.style.left=`${i.left}px`,t.style.width=`${i.width}px`;const a=e.querySelector(d),n=a?a.getBoundingClientRect().bottom:i.top,p=i.bottom-n,v=s<=p,u=i.bottom<=c;v?u?(t.style.top="auto",t.style.bottom=`${c-i.bottom+l}px`):(t.style.top="auto",t.style.bottom=`${l}px`):(t.style.bottom="auto",t.style.top=`${n}px`)}static remove(t){var e;const o=r.get(t);o&&(window.removeEventListener("scroll",o.onScroll),window.removeEventListener("resize",o.onScroll),o.resizeObserver.disconnect(),t.container.parentNode===o.container&&((e=o.container.parentNode)===null||e===void 0||e.insertBefore(t.container,o.container)),y.safeRemove(o.container),r.delete(t))}static isInstalled(t){return r.has(t)}static setPanelHeight(t,e){const o=r.get(t);o&&o.container.style.setProperty("--flight-panel-height",`${e}px`)}static refresh(t){const e=r.get(t);e&&this.updatePosition(e.container,e.anchor,e.options)}};b(h,"UIFlightPosition");let f=h;export{f as UIFlightPosition};