UNPKG

jodit-pro

Version:

PRO Version of Jodit Editor

2 lines (1 loc) 3.37 kB
var g=Object.defineProperty;var c=(i,t)=>g(i,"name",{value:t,configurable:!0});var u,l=function(i,t,e,s){var n=arguments.length,o=n<3?t:s===null?s=Object.getOwnPropertyDescriptor(t,e):s,r;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")o=Reflect.decorate(i,t,e,s);else for(var h=i.length-1;h>=0;h--)(r=i[h])&&(o=(n<3?r(o):n>3?r(t,e,o):r(t,e))||o);return n>3&&o&&Object.defineProperty(t,e,o),o};import{ViewComponent as I}from"jodit/esm/core/component/index.js";import{component as C,debounce as d,watch as f}from"jodit/esm/core/decorators/index.js";let a=(u=class extends I{className(){return"LoadingManager"}constructor(t,e){super(t),this.state=e,this.__tick=0,this.offset=0,this.countInOneChunk=20,this.stopLoadingParts=!1,this.__isLoadingPart=!1,this.__callQueueCount=0}async onUpdateFileBrowser(){this.state.activeElements=[],this.j.panel.setMod("loading",!0),await Promise.all([this.loadFolders(),this.loadItems()]),this.j.panel.setMod("loading",!1)}async loadFolders(){if(!this.j.isOpened)return;const{currentPath:t,currentSource:e}=this.state;try{const s=await this.j.dataProvider.tree(t,e);this.j.stateManager.fillTreeForPath(s,t),this.state.sources=s}catch(s){this.j.status(s)}}async loadItems(){if(this.j.isOpened)try{this.__tick+=1;const{__tick:t}=this;this.offset=0,this.stopLoadingParts=!1,this.__callQueueCount=0;const{items:e,loadedTotal:s}=await _(this.state,this.j.dataProvider,this.offset,this.countInOneChunk);if(this.state.elements=e,this.stopLoadingParts=s<this.countInOneChunk,await this.loadItemsChunk(t),await this.async.requestIdlePromise(),this.__tick!==t)return;for(;!this.stopLoadingParts&&this.j.panel.countInColumn*this.j.panel.countInRow>=this.state.elements.length;)if(await this.loadItemsChunk(t),this.__tick!==t)return}catch(t){this.j.status(t)}}async __loadItemsChunk(t){if(this.__isLoadingPart){this.__callQueueCount+=1;return}if(this.stopLoadingParts){this.__callQueueCount=0;return}this.__isLoadingPart=!0,this.j.panel.items.setMod("chunk-loading",!0);try{this.offset+=this.countInOneChunk;const{items:e,loadedTotal:s}=await _(this.state,this.j.dataProvider,this.offset,this.countInOneChunk);if(this.__tick!==t)return;this.stopLoadingParts=s<this.countInOneChunk,e.length&&(this.state.elements=this.state.elements.concat(e))}catch(e){this.j.status(e)}if(this.j.panel.items.setMod("chunk-loading",!1),this.__isLoadingPart=!1,this.__callQueueCount>0)return this.__callQueueCount-=1,this.__loadItemsChunk(t)}loadItemsChunk(t=this.__tick){return t!==this.__tick?Promise.resolve():this.__loadItemsChunk(t)}},c(u,"LoadingManager"),u);l([f(":update.filebrowser")],a.prototype,"onUpdateFileBrowser",null),l([f(["state.currentPath","state.currentSource"]),d(i=>({timeout:i.defaultTimeout,promisify:!0}))],a.prototype,"loadFolders",null),l([f(["state.currentPath","state.currentSource","state.sortBy","state.onlyImages","state.foldersPosition","state.filterWord"]),d(i=>({timeout:i.defaultTimeout,promisify:!0}))],a.prototype,"loadItems",null),l([d(i=>({timeout:i.defaultTimeout,promisify:!0}))],a.prototype,"loadItemsChunk",null),a=l([C],a);function _(i,t,e,s){const{currentPath:n,currentSource:o,sortBy:r,withFolders:h,foldersPosition:m,onlyImages:p,filterWord:P}=i;return t.itemsEx(n,o,{offset:e,limit:s,sortBy:r,withFolders:h,foldersPosition:m,onlyImages:p,filterWord:P})}c(_,"loadPartItems");export{a as LoadingManager};