UNPKG

jodit-pro

Version:

PRO Version of Jodit Editor

4 lines (3 loc) 2.95 kB
var m=Object.defineProperty;var d=(h,t)=>m(h,"name",{value:t,configurable:!0});var p,s=function(h,t,o,i){var r=arguments.length,e=r<3?t:i===null?i=Object.getOwnPropertyDescriptor(t,o):i,l;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")e=Reflect.decorate(h,t,o,i);else for(var u=h.length-1;u>=0;u--)(l=h[u])&&(e=(r<3?l(e):r>3?l(t,o,e):l(t,o))||e);return r>3&&e&&Object.defineProperty(t,o,e),e};import{component as T,idle as b,throttle as g,watch as c}from"jodit/esm/core/decorators/index.js";import{Dom as f}from"jodit/esm/core/dom/index.js";import{assert as j,css as a,position as k}from"jodit/esm/core/helpers/index.js";import{Popup as w,UIElement as P}from"jodit/esm/core/ui/index.js";import{makeCollection as v}from"jodit/esm/modules/toolbar/factory.js";let n=(p=class extends P{constructor(){super(...arguments),this.isShown=!1,this.toolbar=v(this.j,this),this.popup=new w(this.j,!1)}className(){return"UITuner"}render(){return`<div> <div class='&__handle' title='~Click to tune~'/> </div>`}show(){const t=this.j.s.current();if(!t)return this.hide();const o=f.isBlock(t)?t:f.closest(t,i=>!!(i&&this.j.o.tuneBlock.popup[i.nodeName.toLowerCase()]),this.j.editor);if(!o||o===this.j.editor||!this.j.o.tuneBlock.popup[o.tagName.toLowerCase()])return this.hide();this.currentBlock=o,this.isShown=!0,this.closeToolbar(),this.calcPosition(),this.container.parentNode||this.j.workplace.append(this.container)}hide(){this.isShown&&(this.isShown=!1,f.safeRemove(this.container),this.closeToolbar())}onEditorScroll(){this.isShown&&this.calcPosition()}calcPosition(){const o=a(this.j.editor,"marginLeft"),i=a(this.j.editor,"paddingLeft"),r=a(this.j.editor,"marginTop"),e=this.currentBlock.offsetWidth-15+o+i,l=this.currentBlock.offsetTop-this.j.editor.scrollTop+r;a(this.container,{transform:`translate3d(${e}px, ${l}px, 0)`}),this.popup.isOpened&&this.popup.updatePosition()}onAfterExecTune(t){t&&(this.currentBlock=t),this.calcPosition(),this.openToolbar()}onClickPrevent(t){t.preventDefault(),t.stopPropagation()}onTargetClick(){this.toggleToolbar()}openToolbar(){if(this.setMod("opened",!0),this.toolbar.build(this.j.o.tuneBlock.popup[this.currentBlock.tagName.toLowerCase()],this.currentBlock),this.popup.setContent(this.toolbar.container),!this.popup.isOpened){const t=this.getElm("handle");j(t!=null,"Handle element does not exist"),this.popup.open(()=>k(t))}}closeToolbar(){this.setMod("opened",!1),this.popup.close()}toggleToolbar(){this.getMod("opened")?this.closeToolbar():this.openToolbar()}},d(p,"UITuner"),p);s([c(":hideTuner.tune")],n.prototype,"hide",null),s([c("j.editor:scroll"),g(10)],n.prototype,"onEditorScroll",null),s([c(":afterExecTune.tune"),b()],n.prototype,"onAfterExecTune",null),s([c("container:click container:mousedown")],n.prototype,"onClickPrevent",null),s([c("handle:click")],n.prototype,"onTargetClick",null),s([c(":closeTuner.tune")],n.prototype,"closeToolbar",null),n=s([T],n);export{n as UITuner};