UNPKG

jodit-pro

Version:

PRO Version of Jodit Editor

2 lines (1 loc) 2.24 kB
var f=Object.defineProperty;var p=(h,t)=>f(h,"name",{value:t,configurable:!0});var o,c=function(h,t,e,s){var r=arguments.length,n=r<3?t:s===null?s=Object.getOwnPropertyDescriptor(t,e):s,u;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")n=Reflect.decorate(h,t,e,s);else for(var a=h.length-1;a>=0;a--)(u=h[a])&&(n=(r<3?u(n):r>3?u(t,e,n):u(t,e))||n);return r>3&&n&&Object.defineProperty(t,e,n),n};import{ViewComponent as y}from"jodit/esm/core/component/view-component.js";import{component as d,watch as l}from"jodit/esm/core/decorators/index.js";import{fastClone as m}from"jodit/esm/core/helpers/utils/extend.js";let i=(o=class extends y{className(){return"HistoryManager"}constructor(t,e){super(t),this.state=e,this.history=[],this.historyIndex=0}canNext(){return this.historyIndex<this.history.length-1}canPrevious(){return this.historyIndex>0}push(t){let{historyIndex:e}=this;const s=this.history[e];if(s&&s.currentSource===t.currentSource&&s.currentPath===t.currentPath)return;let r=[...this.history];r.length-1!==e&&(r=r.slice(0,e+1)),r.push(t),s&&(e+=1),this.history=r,this.historyIndex=e}next(){this.canNext()&&(this.historyIndex+=1,this.updateState())}previous(){this.canPrevious()&&(this.historyIndex-=1,this.updateState())}updateCurrent(){this.history[this.historyIndex]={currentSource:this.state.currentSource,currentPath:this.state.currentPath,tree:m(this.state.tree),elements:[...this.state.elements]}}onHome(){this.state.currentPath="",this.state.currentSource="",this.j.e.fire("afterOpenFolder.filebrowser update.filebrowser")}onOpenFolder(){this.push({tree:[],elements:[],currentPath:this.state.currentPath,currentSource:this.state.currentSource}),this.j.e.fire("changeSelection")}updateState(){const{tree:t,elements:e,currentSource:s,currentPath:r}=this.history[this.historyIndex];this.state.activeElements=[],this.state.elements=[...e],this.state.tree=[...t],this.state.currentSource=s,this.state.currentPath=r,this.j.e.fire("changeSelection")}},p(o,"HistoryManager"),o);c([l(["state.elements","state.tree"])],i.prototype,"updateCurrent",null),c([l(":goHome.filebrowser")],i.prototype,"onHome",null),c([l(":afterOpenFolder.filebrowser")],i.prototype,"onOpenFolder",null),i=c([d],i);export{i as HistoryManager};