UNPKG

jodit-pro

Version:

PRO Version of Jodit Editor

2 lines (1 loc) 2.55 kB
var I=Object.defineProperty;var l=(s,e)=>I(s,"name",{value:e,configurable:!0});var c=function(s,e,t,i){var r=arguments.length,n=r<3?e:i===null?i=Object.getOwnPropertyDescriptor(e,t):i,a;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")n=Reflect.decorate(s,e,t,i);else for(var h=s.length-1;h>=0;h--)(a=s[h])&&(n=(r<3?a(n):r>3?a(e,t,n):a(e,t))||n);return r>3&&n&&Object.defineProperty(e,t,n),n};import{autobind as f}from"jodit/esm/core/decorators/index.js";const u=class u{constructor(e){this.state=e}getIndex(e,t=this.state.elements){return t.findIndex(i=>i.uniqueHashKey===e.uniqueHashKey)}isActive(e){return!!this.state.activeElements.find(t=>t.uniqueHashKey===e.uniqueHashKey)}isFavorite(e){return!!this.state.favorites.find(t=>t.uniqueHashKey===e.uniqueHashKey)}addActive(e,t){var i;this.state.metaInfo=e,this.state.info=(i=e.file)!==null&&i!==void 0?i:"",this.state.lastSelectedIndex=this.getIndex(e),this.state.activeElements=t?[...this.state.activeElements,e]:[e]}callSelectHandler(){var e;const t=this.state.activeElements;(e=this.state.onSelectCallBack)===null||e===void 0||e.call(this,{baseurl:"",files:t.map(i=>i.fileURL),isImages:t.map(i=>!!i.isImage)})}setFilter(e){this.state.filterWord=e}toggleFavorite(e){const t=this.getIndex(e,this.state.favorites),i=[...this.state.favorites];t===-1?i.push(e):i.splice(t,1),this.state.favorites=i}fillTreeForPath(e,t){if(!this.state.tree.length||!t||t==="/"){this.state.tree=e.map(m);return}this.removeActive(this.state.tree),e.forEach(i=>{let r=v(this.state.tree,i.name);r||(r=m(i),this.state.tree.push(r)),r.isActive=!0;const n=y(t,r);n&&(n.isActive=!0,n.children=d(i.folders).map(a=>p(a,t+"/"+a,i.name)))}),this.state.tree=[...this.state.tree]}removeActive(e){e.forEach(t=>{t.isActive=!1,this.removeActive(t.children)})}get isFavoriteItems(){return this.state.favorites===this.state.elements}};l(u,"StateManager");let o=u;c([f],o.prototype,"getIndex",null),c([f],o.prototype,"isActive",null),c([f],o.prototype,"isFavorite",null);function y(s,e){return s.split("/").reduce((t,i)=>t&&v(t.children,i),e)}l(y,"findTreeItem");function v(s,e){var t;return(t=s.find(i=>i.name===e))!==null&&t!==void 0?t:null}l(v,"findItem");function d(s){return s.filter(e=>e!=="."&&e!=="..")}l(d,"filterFolders");function m(s){return{type:"source",name:s.name,title:s.title,sourceName:s.name,path:"/",children:d(s.folders).map(e=>p(e,e,s.name))}}l(m,"sourceToTreeItem");function p(s,e,t){return{type:"directory",name:s,path:e,sourceName:t,children:[]}}l(p,"folderToTreeItem");export{o as StateManager};