UNPKG

jodit-pro

Version:

PRO Version of Jodit Editor

2 lines (1 loc) 10.4 kB
var E=Object.defineProperty;var d=(m,e)=>E(m,"name",{value:e,configurable:!0});var u,o=function(m,e,t,s){var i=arguments.length,n=i<3?e:s===null?s=Object.getOwnPropertyDescriptor(e,t):s,h;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")n=Reflect.decorate(m,e,t,s);else for(var l=m.length-1;l>=0;l--)(h=m[l])&&(n=(i<3?h(n):i>3?h(e,t,n):h(e,t))||n);return i>3&&n&&Object.defineProperty(e,t,n),n};import"./ui/assets/icons/index.js";import{ContextMenuManager as M}from"./helpers/context-menu.js";import{parentPath as c}from"./helpers/helpers.js";import{HistoryManager as S}from"./helpers/history-manager.js";import{LoadingManager as F}from"./helpers/loading-manager.js";import{PersistentStore as _}from"./helpers/persistent-store.js";import{StateManager as C}from"./helpers/state-manager.js";import{UIBrowserHeader as I}from"./ui/header/header.js";import{UILightBox as B}from"./ui/lightboox/lightbox.js";import{UIBrowserPanel as O}from"./ui/panel/panel.js";import{UIProgress as L}from"./ui/progress/progress.js";import{Config as p}from"jodit/esm/config.js";import{IS_PROD as x,KEY_DELETE as D,KEY_DOWN as b,KEY_ENTER as k,KEY_LEFT as y,KEY_RIGHT as f,KEY_UP as U}from"jodit/esm/core/constants.js";import{autobind as g,cache as K,component as N,derive as z,watch as a}from"jodit/esm/core/decorators/index.js";import{ConfigProto as v,css as T,isAbortError as j,isString as P,isValidName as R}from"jodit/esm/core/helpers/index.js";import{Dlgs as H}from"jodit/esm/core/traits/dlgs.js";import{Dom as W,observable as G}from"jodit/esm/modules/index.js";import{Dialog as Y}from"jodit/esm/modules/dialog/index.js";import{makeDataProvider as A}from"jodit/esm/modules/file-browser/factories.js";import{openImageEditor as J}from"jodit/esm/modules/image-editor/image-editor.js";import{JoditPro as w}from"../../jodit-pro.js";import{license as V}from"../license/license.js";let r=(u=class extends Y{className(){return"FileBrowserPro"}lock(e="any"){return this.container.classList.add("jodit_disabled"),super.lock(e)}unlock(){return this.container.classList.remove("jodit_disabled"),super.unlock()}status(e,t=!(e instanceof Error)){j(e)||(!x&&!P(e)&&console.error(e),this.message.message(P(e)?e:e.message,t?"success":"error",this.options.howLongShowMsg))}get progressbar(){return new L(this,this.stateManager.state)}constructor(e){super(v(Object.assign(e||{},{resizable:!0,draggable:!0,toolbarButtons:e?.toolbarButtons||p.defaultOptions.filebrowser.buttons,buttons:w.atom(["filebrowser.settings","fullsize","dialog.close"])}),p.defaultOptions.filebrowser)),this.dataProvider=A(this,this.options),this.state=G({onSelectCallBack:null,theme:"default",showSideBar:!0,showFavorites:!0,showSettings:!1,showPreview:!1,withFolders:!0,foldersPosition:"bottom",info:"",metaInfo:null,currentPath:"",currentSource:"",currentBaseUrl:"",tree:[],activeElements:[],favorites:[],progress:0,lastSelectedIndex:0,elements:[],messages:[],sources:[],view:"tiles",tileSize:"default",sortBy:"name-asc",filterWord:"",onlyImages:!1}),this.persistent=new _(this,this.state),this.loadingManager=new F(this,this.state),this.stateManager=new C(this.state),this.historyManager=new S(this,this.state),this.contextMenuManager=new M(this),this.header=new I(this,this.options,this.stateManager),this.panel=new O(this,this.stateManager),this.files=this.panel,this.tree=this.panel,V.make(this),!this.persistent.theme&&this.options.theme&&(this.persistent.theme=this.options.theme),this.panel.append(this.progressbar),this.toolbar.setMod("mode","header"),this.setSize(Math.min(this.options.width,screen.width),Math.min(this.options.height,screen.height)).setHeader(this.header),this.onResizeWindow(),this.initUploader(),this.onChangeTheme(),this.fullFillOptions(),this.dataProvider.onProgress(t=>{t===0&&(t=30),this.state.progress=t}),this.e.on("beforeClose",this.removeGlobalListeners),this.e.fire("afterInit"),w.prototype.afterInitHook.call(this)}addDisclaimer(e){this.dialog.appendChild(e)}async open(e=this.o.defaultCallback,t){return this.state.onlyImages=!!t,this.prepareOpening(e),super.open(this.panel.container),this.e.fire("update.filebrowser")}onResizeWindow(){T(this.dialog,{maxWidth:screen.width,minHeight:Math.min(this.options.height,screen.height),minWidth:Math.min(this.options.width,screen.width)})}onChangePath(){const{currentPath:e,currentSource:t}=this.state;this.uploader.setPath(e),this.uploader.setSource(t)}onChangeTheme(){this.setMod("theme",this.state.theme),this.header.setMod("theme",this.state.theme),this.panel.setMod("theme",this.state.theme),this.options.theme=this.state.theme}onToggleSettings(){this.state.showSettings=!this.state.showSettings}prepareOpening(e){this.registerGlobalListeners(),e&&(this.state.onSelectCallBack=t=>{this.close(),e(t)}),this.persistent.syncWithState()}registerGlobalListeners(){this.e.on(this.ow,"keydown",this.onKeyPress)}onKeyPress(e){const{activeElement:t}=this.od;if(!this.state.activeElements.length||!t||!W.isOrContains(this.panel.items.container,t))return;const s=this.state.elements;switch(e.key){case k:return this.onChooseItems();case D:return this.onFileRemove();case f:case y:case b:case U:{const i=e.key===f||e.key===b,n=this.state.lastSelectedIndex;let h;if([f,y].includes(e.key))i?h=s[n+1]?n+1:0:h=s[n-1]?n-1:s.length-1;else{const{countInRow:l}=this.panel;h=Math.round(((n+1)/l+(i?1:-1))*l-1)}return s[h]&&this.stateManager.addActive(s[h],e.shiftKey),!1}}}removeGlobalListeners(){this.e.off(this.ow,"keydown",this.onKeyPress)}onFileRemove(){this.state.activeElements.length&&this.confirm("Are you sure?","Delete",e=>{e&&this.__itemsRemove(this.state.activeElements)}).bindDestruct(this)}__itemsRemove(e){if(!e.length)return Promise.resolve();const t=[];return e.forEach(s=>{var i;t.push(s.type==="folder"?this.__folderRemove(c(s.path),(i=s.name)!==null&&i!==void 0?i:"",s.sourceName):this.__removeFile(s.file||s.name||"",s.sourceName))}),this.state.activeElements.forEach(s=>{this.stateManager.isFavorite(s)&&this.stateManager.toggleFavorite(s)}),this.state.activeElements=[],Promise.allSettled(t).then(()=>Promise.allSettled([this.loadingManager.loadItems(),this.loadingManager.loadFolders()]))}__removeFile(e,t){return this.dataProvider.fileRemove(this.state.currentPath,e,t).then(s=>{this.status(s||this.i18n('File "%s" was deleted',e),!0)}).catch(this.status)}__folderRemove(e,t,s){return this.dataProvider.folderRemove(e,t,s).then(i=>{this.status(i||this.i18n('Folder "%s" was deleted',t),!0),this.state.currentPath===e&&(this.state.currentPath=c(e),this.state.currentSource=s)}).catch(this.status)}onFileEdit(){if(this.state.activeElements.length===1){const[e]=this.state.activeElements;J.call(this,e.fileURL,e.file||"",e.path,e.sourceName,void 0,this.status)}}onFolderRename(e){this.prompt("Enter new name","Rename",t=>{if(!R(t)||t===e.name)return this.status(this.i18n("Enter new name")),!1;this.dataProvider.folderRename(c(e.path),e.name,t,e.sourceName).then(s=>{this.state.activeElements=[],this.status(s,!0),this.state.currentPath=c(e.path)+"/"+t,this.state.currentSource=e.sourceName,this.historyManager.updateCurrent(),this.loadingManager.loadFolders()}).catch(this.status)},this.i18n("type name"),e.name).bindDestruct(this)}onFolderRemove(e){this.confirm("Are you sure?","Delete",t=>{t&&this.__itemsRemove([{type:"folder",name:e.name,path:e.path,sourceName:e.sourceName}])}).bindDestruct(this)}onFolderCreate(e){this.prompt("Enter Directory name","Create directory",t=>{const s=e.path||"/";this.dataProvider.createFolder(t,e.path||"/",e.sourceName).then(()=>{this.state.currentSource===e.sourceName&&this.state.currentPath===s?this.e.fire("update.filebrowser"):(this.state.currentSource=e.sourceName,this.state.currentPath=s),this.historyManager.updateCurrent()},this.status)},this.i18n("type name")).bindDestruct(this)}onFileRename(e){const t=e.file||e.name||"";this.state.activeElements.length===1&&t&&this.prompt("Enter new name","Rename",s=>{if(!R(s))return this.status(this.i18n("Enter new name")),!1;this.dataProvider.fileRename(this.state.currentPath,t,s,this.state.currentSource).then(i=>{this.state.activeElements=[],this.status(i,!0),this.loadingManager.loadItems()}).catch(this.status)},this.i18n("type name"),t).bindDestruct(this)}onChooseItems(){const e=this.stateManager.state.activeElements;if(e.length){if(e[0].type==="folder"){this.state.currentPath=this.state.currentPath+"/"+e[0].name,this.state.currentSource=e[0].sourceName,this.e.fire("afterOpenFolder.filebrowser");return}this.state.onSelectCallBack?this.stateManager.callSelectHandler():this.onOpenLightBox(e[0])}}onOpenLightBox(e){B.open(this,e,this.state.elements)}initUploader(){const e=this,t=v(e.o.uploader||{},p.defaultOptions.uploader),s=d(()=>this.loadingManager.loadItems(),"uploadHandler");e.uploader=e.getInstance("Uploader",t),e.uploader.bind(e.panel.container,s,e.status),e.e.on("bindUploader.filebrowser",i=>{e.uploader.bind(i,s,e.status)})}destruct(){this.removeGlobalListeners(),this.header.destruct(),this.panel.destruct(),super.destruct()}fullFillOptions(){["getLocalFileByUrl","crop","resize","create","fileMove","folderMove","fileRename","folderRename","fileRemove","folderRemove","folder","items","permissions"].forEach(t=>{this.options[t]!=null&&(this.options[t]=v(this.options[t],this.o.ajax))})}},d(u,"FileBrowserPro"),u);o([g],r.prototype,"status",null),o([K],r.prototype,"progressbar",null),o([a(":resize",{context:window})],r.prototype,"onResizeWindow",null),o([a(["state.currentPath","state.currentSource"])],r.prototype,"onChangePath",null),o([a("state.theme")],r.prototype,"onChangeTheme",null),o([a(":toggleSettings.filebrowser")],r.prototype,"onToggleSettings",null),o([g],r.prototype,"onKeyPress",null),o([g],r.prototype,"removeGlobalListeners",null),o([a(":fileRemove.filebrowser")],r.prototype,"onFileRemove",null),o([a(":edit.filebrowser")],r.prototype,"onFileEdit",null),o([a(":folderRename.filebrowser")],r.prototype,"onFolderRename",null),o([a(":folderRemove.filebrowser")],r.prototype,"onFolderRemove",null),o([a(":folderCreate.filebrowser")],r.prototype,"onFolderCreate",null),o([a(":fileRename.filebrowser")],r.prototype,"onFileRename",null),o([a(":select.filebrowser")],r.prototype,"onChooseItems",null),o([a(":openLightBox.filebrowser")],r.prototype,"onOpenLightBox",null),r=o([N,z(H)],r);Object.defineProperty(w.modules,"FileBrowserPro",{value:r,writable:!1,enumerable:!0,configurable:!0});export{r as FileBrowserPro};