UNPKG

jodit-pro

Version:

PRO Version of Jodit Editor

2 lines (1 loc) 2.28 kB
var g=Object.defineProperty;var p=(h,t)=>g(h,"name",{value:t,configurable:!0});var o,r=function(h,t,e,s){var l=arguments.length,a=l<3?t:s===null?s=Object.getOwnPropertyDescriptor(t,e):s,n;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")a=Reflect.decorate(h,t,e,s);else for(var d=h.length-1;d>=0;d--)(n=h[d])&&(a=(l<3?n(a):l>3?n(t,e,a):n(t,e))||a);return l>3&&a&&Object.defineProperty(t,e,a),a};import{autobind as f,component as j,watch as u}from"jodit/esm/core/decorators/index.js";import{assert as c,css as v}from"jodit/esm/core/helpers/index.js";import{UIInput as m}from"jodit/esm/core/ui/index.js";let i=(o=class extends m{className(){return"UIRange"}constructor(t,e){super(t,{...e,type:"hidden"}),this.state={...m.defaultState,min:0,max:100,step:1},this.startValue=0,this.startX=0,this.width=100,Object.assign(this.state,e),this.appendUIRange(),this.onChangeSelfValue()}appendUIRange(){const t=this.j.create.div(this.getFullElName("slider"));this.container.appendChild(t);const e=this.j.create.div(this.getFullElName("handle"));t.appendChild(e);const s=this.j.create.div(this.getFullElName("log")),l=this.getElm("label");l&&l.appendChild(s)}onDragStart(t){this.startValue=parseFloat(this.value)||0,this.startX=t.clientX;const e=this.getElm("slider");c(e!=null,"slider element does not exists"),this.width=e.offsetWidth,this.j.e.on(this.j.ow,"mousemove",this.onDrag)}onDrag(t){const{min:e,max:s,step:l=1}=this.state,a=(t.clientX-this.startX)/this.width*(this.state.max-this.state.min);let n=this.startValue+a;n<e&&(n=e),n>s&&(n=s),n=Math.round(n/l)*l,this.value=n.toFixed(10)}onDragEnd(){this.j.e.off(this.j.ow,"mousemove",this.onDrag)}onChangeSelfValue(){const t=this.getElm("handle"),e=parseFloat(this.value)||0;c(t!=null,"Handle element does not exist"),v(t,{left:(e-this.state.min)/(this.state.max-this.state.min)*100+"%"});const s=this.getElm("log");c(s!=null,"log element does not exist"),s.innerText=e.toString()}destruct(){return this.onDragEnd(),super.destruct()}},p(o,"UIRange"),o);r([u(["handle:mousedown","handle:touchstart"])],i.prototype,"onDragStart",null),r([f],i.prototype,"onDrag",null),r([u(["j.ow:mouseup","j.ow:touchend"])],i.prototype,"onDragEnd",null),r([u(":change")],i.prototype,"onChangeSelfValue",null),i=r([j],i);export{i as UIRange};