UNPKG

jodit-pro

Version:

PRO Version of Jodit Editor

7 lines (6 loc) 2.5 kB
var v=Object.defineProperty;var p=(r,e)=>v(r,"name",{value:e,configurable:!0});var a,d=function(r,e,i,t){var s=arguments.length,o=s<3?e:t===null?t=Object.getOwnPropertyDescriptor(e,i):t,l;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(r,e,i,t);else for(var n=r.length-1;n>=0;n--)(l=r[n])&&(o=(s<3?l(o):s>3?l(e,i,o):l(e,i))||o);return s>3&&o&&Object.defineProperty(e,i,o),o};import{component as I,debounce as _,hook as M,watch as u}from"jodit/esm/core/decorators/index.js";import{Dom as y}from"jodit/esm/core/dom/dom.js";import{css as f,loadImage as w}from"jodit/esm/core/helpers/utils/index.js";import{assert as h}from"jodit/esm/core/helpers/utils/assert.js";import{UIGroup as b}from"jodit/esm/core/ui/group/group.js";import{UIBrowserItem as c}from"../item/item.js";import{UIResize as g}from"../../../../traits/resize/resize.js";let m=(a=class extends b{className(){return"UIPreview"}addResize(){f(this.container,{width:null,height:null}),g.remove(this),g.install(this,screen.width>450?"left":"top")}render(){return`<div> <div class="&__image"></div> <div class="&__info"></div> <div class="&__loader"></div> <div class="&__empty-message">~Select image~</div> </div>`}constructor(e,i){super(e),this.state=i,this.lastLoadPromise=null,this.onChangeMetaInfo()}afterSetMod(e,i){e==="hidden"&&i===!1&&this.onChangeMetaInfo(),super.afterSetMod(e,i)}onChangeMetaInfo(){var e,i;if(this.getMod("hidden"))return;const{metaInfo:t}=this.state;this.setMod("empty",!t);const s=this.getElm("info");h(s!=null,"info element does not exists"),y.detach(s);const o=this.getElm("image");h(o!=null,"image element does not exists"),f(o,{backgroundImage:null}),t&&(this.setMod("is-file",t.isImage===!1).setMod("type",(e=t.type)!==null&&e!==void 0?e:"file"),c.prototype.setElementValue.call(this,"name",t.file),c.prototype.setElementValue.call(this,"time",t.time),c.prototype.setElementValue.call(this,"filesize",t.size),this.setMod("loading",!0),(i=this.lastLoadPromise)===null||i===void 0||i.rejectCallback(),this.lastLoadPromise=w(t.isImage?t.fileURL:t.imageURL,this.j),this.lastLoadPromise.then(l=>{const n=this.getElm("image");h(n!=null,"image element does not exist"),l&&f(n,{backgroundImage:`url(${l.src})`})}).finally(()=>{this.setMod("loading",!1)}).catch(()=>{}))}},p(a,"UIPreview"),a);d([M("ready"),u(":resize",{context:window}),_()],m.prototype,"addResize",null),d([u("state.metaInfo")],m.prototype,"onChangeMetaInfo",null),m=d([I],m);export{m as UIPreview};