|
"use strict";(self.webpackChunk_JUPYTERLAB_CORE_OUTPUT=self.webpackChunk_JUPYTERLAB_CORE_OUTPUT||[]).push([[7543],{37543:(e,t,s)=>{s.r(t),s.d(t,{DocumentManager:()=>M,DocumentWidgetManager:()=>x,IDocumentManager:()=>A,IDocumentWidgetOpener:()=>E,IRecentsManager:()=>I,PathStatus:()=>F,RecentsManager:()=>N,SaveHandler:()=>f,SavingStatus:()=>W,isValidFileName:()=>d,renameDialog:()=>c,renameFile:()=>l,shouldOverwrite:()=>h});var n,i=s(53312),a=s(68722),o=s(12030),r=s(63485);function c(e,t,s){const n=(s=s||o.nullTranslator).load("jupyterlab"),a=t.localPath.split("/").pop()||t.localPath;return(0,i.showDialog)({title:n.__("Rename File"),body:new g(a),focusNodeSelector:"input",buttons:[i.Dialog.cancelButton(),i.Dialog.okButton({label:n.__("Rename"),ariaLabel:n.__("Rename File")})]}).then((e=>e.value?d(e.value)?t.rename(e.value):((0,i.showErrorMessage)(n.__("Rename Error"),Error(n.__('"%1" is not a valid name for a file. Names must have nonzero length, and cannot include "/", "\\", or ":"',e.value))),null):null))}function l(e,t,s){return e.rename(t,s).catch((n=>{if(409!==n.response.status)throw n;return h(s).then((n=>n?e.overwrite(t,s):Promise.reject("File not renamed")))}))}function h(e,t){const s=(t=t||o.nullTranslator).load("jupyterlab"),n={title:s.__("Overwrite file?"),body:s.__('"%1" already exists, overwrite?',e),buttons:[i.Dialog.cancelButton(),i.Dialog.warnButton({label:s.__("Overwrite"),ariaLabel:s.__("Overwrite Existing File")})]};return(0,i.showDialog)(n).then((e=>Promise.resolve(e.button.accept)))}function d(e){return e.length>0&&!/[\/\\:]/.test(e)}class g extends r.Widget{constructor(e){super({node:n.createRenameNode(e)}),this.addClass("jp-FileDialog");const t=a.PathExt.extname(e),s=this.inputNode.value=a.PathExt.basename(e);this.inputNode.setSelectionRange(0,s.length-t.length)}get inputNode(){return this.node.getElementsByTagName("input")[0]}getValue(){return this.inputNode.value}}!function(e){e.createRenameNode=function(e,t){const s=(t=t||o.nullTranslator).load("jupyterlab"),n=document.createElement("div"),i=document.createElement("label");i.textContent=s.__("File Path");const a=document.createElement("span");a.textContent=e;const r=document.createElement("label");r.textContent=s.__("New Name"),r.className="jp-new-name-title";const c=document.createElement("input");return n.appendChild(i),n.appendChild(a),n.appendChild(r),n.appendChild(c),n}}(n||(n={}));var _=s(65903),u=s(33625),m=s(20998),p=s(14421),v=s(81997);class f{constructor(e){this._autosaveTimer=-1,this._minInterval=-1,this._interval=-1,this._isActive=!1,this._inDialog=!1,this._isDisposed=!1,this._multiplier=10,this._context=e.context,this._isConnectedCallback=e.isConnectedCallback||(()=>!0);const t=e.saveInterval||120;this._minInterval=1e3*t,this._interval=this._minInterval,this._context.fileChanged.connect(this._setTimer,this),this._context.disposed.connect(this.dispose,this)}get saveInterval(){return this._interval/1e3}set saveInterval(e){this._minInterval=this._interval=1e3*e,this._isActive&&this._setTimer()}get isActive(){return this._isActive}get isDisposed(){return this._isDisposed}dispose(){this.isDisposed||(this._isDisposed=!0,clearTimeout(this._autosaveTimer),v.Signal.clearData(this))}start(){this._isActive=!0,this._setTimer()}stop(){this._isActive=!1,clearTimeout(this._autosaveTimer)}_setTimer(){clearTimeout(this._autosaveTimer),this._isActive&&(this._autosaveTimer=window.setTimeout((()=>{this._isConnectedCallback()&&this._save()}),this._interval))}_save(){const e=this._context;if(this._setTimer(),!e)return;if(!e.contentsModel||!e.contentsModel.writable||!e.model.dirty||this._inDialog)return;const t=(new Date).getTime();e.save().then((()=>{if(this.isDisposed)return;const e=(new Date).getTime()-t;this._interval=Math.max(this._multiplier*e,this._minInterval),this._setTimer()})).catch((e=>{const{name:t}=e;"ModalCancelError"!==t&&"ModalDuplicateError"!==t&&console.error("Error in Auto-Save",e.message)}))}}var w,y,C=s(2549),D=s(49503);class x{constructor(e){this._activateRequested=new v.Signal(this),this._confirmClosingTab=!1,this._isDisposed=!1,this._stateChanged=new v.Signal(this),this._registry=e.registry,this.translator=e.translator||o.nullTranslator,this._recentsManager=e.recentsManager||null}get activateRequested(){return this._activateRequested}get confirmClosingDocument(){return this._confirmClosingTab}set confirmClosingDocument(e){if(this._confirmClosingTab!==e){const t=this._confirmClosingTab;this._confirmClosingTab=e,this._stateChanged.emit({name:"confirmClosingDocument",oldValue:t,newValue:e})}}get stateChanged(){return this._stateChanged}get isDisposed(){return this._isDisposed}dispose(){this.isDisposed||(this._isDisposed=!0,v.Signal.disconnectReceiver(this))}createWidget(e,t){const s=e.createNew(t);return this._initializeWidget(s,e,t),s}_initializeWidget(e,t,s){w.factoryProperty.set(e,t);const n=new C.DisposableSet;for(const i of this._registry.widgetExtensions(t.name)){const t=i.createNew(e,s);t&&n.add(t)}w.disposablesProperty.set(e,n),e.disposed.connect(this._onWidgetDisposed,this),this.adoptWidget(s,e),s.fileChanged.connect(this._onFileChanged,this),s.pathChanged.connect(this._onPathChanged,this),s.ready.then((()=>{this.setCaption(e)}))}adoptWidget(e,t){w.widgetsProperty.get(e).push(t),D.MessageLoop.installMessageHook(t,this),t.addClass("jp-Document"),t.title.closable=!0,t.disposed.connect(this._widgetDisposed,this),w.contextProperty.set(t,e)}findWidget(e,t){const s=w.widgetsProperty.get(e);if(s)return(0,u.find)(s,(e=>{const s=w.factoryProperty.get(e);return!!s&&s.name===t}))}contextForWidget(e){return w.contextProperty.get(e)}cloneWidget(e){const t=w.contextProperty.get(e);if(!t)return;const s=w.factoryProperty.get(e);if(!s)return;const n=s.createNew(t,e);return this._initializeWidget(n,s,t),n}closeWidgets(e){const t=w.widgetsProperty.get(e);return Promise.all(t.map((e=>this.onClose(e)))).then((()=>{}))}deleteWidgets(e){const t=w.widgetsProperty.get(e);return Promise.all(t.map((e=>this.onDelete(e)))).then((()=>{}))}messageHook(e,t){switch(t.type){case"close-request":return this.onClose(e),!1;case"activate-request":{const t=e,s=this.contextForWidget(t);s&&(s.ready.then((()=>{this._recordAsRecentlyOpened(t,s.contentsModel)})).catch((()=>{console.warn("Could not record the recents status for",s)})),this._activateRequested.emit(s.path));break}}return!0}async setCaption(e){const t=this.translator.load("jupyterlab"),s=w.contextProperty.get(e);if(!s)return;const n=s.contentsModel;if(n)return s.listCheckpoints().then((i=>{if(e.isDisposed)return;const o=i[i.length-1],r=o?a.Time.format(o.last_modified):"None";let c=t.__("Name: %1\nPath: %2\n",n.name,n.path);s.model.readOnly?c+=t.__("Read-only"):c+=t.__("Last Saved: %1\n",a.Time.format(n.last_modified))+t.__("Last Checkpoint: %1",r),e.title.caption=c}));e.title.caption=""}async onClose(e){var t;const[s,n]=await this._maybeClose(e,this.translator);if(e.isDisposed)return!0;if(s){const s=w.contextProperty.get(e);if(!n){if(!s)return!0;(null===(t=s.contentsModel)||void 0===t?void 0:t.writable)?await s.save():await s.saveAs()}if(s&&("timeout"===await Promise.race([s.ready,new Promise((e=>setTimeout(e,3e3,"timeout")))])?console.warn("Could not record the widget as recently closed because the context did not become ready in 3 seconds"):this._recordAsRecentlyClosed(e,s.contentsModel)),e.isDisposed)return!0;e.dispose()}return s}onDelete(e){return e.dispose(),Promise.resolve(void 0)}_recordAsRecentlyOpened(e,t){var s;const n=this._recentsManager;if(!n)return;const i=t.path,a=this._registry.getFileTypeForModel(t).contentType,o=null===(s=w.factoryProperty.get(e))||void 0===s?void 0:s.name;if(n.addRecent({path:i,contentType:a,factory:o},"opened"),"directory"!==a){const e=i.lastIndexOf("/")>0?i.slice(0,i.lastIndexOf("/")):"";n.addRecent({path:e,contentType:"directory"},"opened")}}_recordAsRecentlyClosed(e,t){var s;const n=this._recentsManager;if(!n)return;const i=t.path,a=this._registry.getFileTypeForModel(t).contentType,o=null===(s=w.factoryProperty.get(e))||void 0===s?void 0:s.name;n.addRecent({path:i,contentType:a,factory:o},"closed")}async _maybeClose(e,t){var s,n;const a=(t=t||o.nullTranslator).load("jupyterlab"),r=w.contextProperty.get(e);if(!r)return Promise.resolve([!0,!0]);let c=w.widgetsProperty.get(r);if(!c)return Promise.resolve([!0,!0]);c=c.filter((e=>{const t=w.factoryProperty.get(e);return!!t&&!1===t.readOnly}));const l=e.title.label,h=w.factoryProperty.get(e),d=r.model.dirty&&c.length<=1&&!(null===(s=null==h?void 0:h.readOnly)||void 0===s||s);if(this.confirmClosingDocument){const e=[i.Dialog.cancelButton(),i.Dialog.okButton({label:d?a.__("Close and save"):a.__("Close"),ariaLabel:d?a.__("Close and save Document"):a.__("Close Document")})];d&&e.splice(1,0,i.Dialog.warnButton({label:a.__("Close without saving"),ariaLabel:a.__("Close Document without saving")}));const t=await(0,i.showDialog)({title:a.__("Confirmation"),body:a.__('Please confirm you want to close "%1".',l),checkbox:d?null:{label:a.__("Do not ask me again."),caption:a.__("If checked, no confirmation to close a document will be asked in the future.")},buttons:e});return t.isChecked&&(this.confirmClosingDocument=!1),Promise.resolve([t.button.accept,!d||"warn"===t.button.displayType])}{if(!d)return Promise.resolve([!0,!0]);const e=(null===(n=r.contentsModel)||void 0===n?void 0:n.writable)?a.__("Save"):a.__("Save as"),t=await(0,i.showDialog)({title:a.__("Save your work"),body:a.__('Save changes in "%1" before closing?',l),buttons:[i.Dialog.cancelButton(),i.Dialog.warnButton({label:a.__("Discard"),ariaLabel:a.__("Discard changes to file")}),i.Dialog.okButton({label:e})]});return[t.button.accept,"warn"===t.button.displayType]}}_widgetDisposed(e){const t=w.contextProperty.get(e);if(!t)return;const s=w.widgetsProperty.get(t);s&&(u.ArrayExt.removeFirstOf(s,e),s.length||t.dispose())}_onWidgetDisposed(e){w.disposablesProperty.get(e).dispose()}_onFileChanged(e){const t=w.widgetsProperty.get(e);for(const e of t)this.setCaption(e)}_onPathChanged(e){const t=w.widgetsProperty.get(e);for(const e of t)this.setCaption(e)}}!function(e){e.contextProperty=new p.AttachedProperty({name:"context",create:()=>{}}),e.factoryProperty=new p.AttachedProperty({name:"factory",create:()=>{}}),e.widgetsProperty=new p.AttachedProperty({name:"widgets",create:()=>[]}),e.disposablesProperty=new p.AttachedProperty({name:"disposables",create:()=>new C.DisposableSet})}(w||(w={}));class M{constructor(e){var t;this._activateRequested=new v.Signal(this),this._contexts=[],this._isDisposed=!1,this._autosave=!0,this._autosaveInterval=120,this._lastModifiedCheckMargin=500,this._renameUntitledFileOnSave=!0,this._stateChanged=new v.Signal(this),this.translator=e.translator||o.nullTranslator,this.registry=e.registry,this.services=e.manager,this._dialogs=null!==(t=e.sessionDialogs)&&void 0!==t?t:new i.SessionContextDialogs({translator:e.translator}),this._isConnectedCallback=e.isConnectedCallback||(()=>!0),this._opener=e.opener,this._when=e.when||e.manager.ready;const s=new x({registry:this.registry,translator:this.translator,recentsManager:e.recentsManager});s.activateRequested.connect(this._onActivateRequested,this),s.stateChanged.connect(this._onWidgetStateChanged,this),this._widgetManager=s,this._setBusy=e.setBusy}get activateRequested(){return this._activateRequested}get autosave(){return this._autosave}set autosave(e){if(this._autosave!==e){const t=this._autosave;this._autosave=e,this._contexts.forEach((t=>{const s=y.saveHandlerProperty.get(t);s&&(!0!==e||s.isActive?!1===e&&s.isActive&&s.stop():s.start())})),this._stateChanged.emit({name:"autosave",oldValue:t,newValue:e})}}get autosaveInterval(){return this._autosaveInterval}set autosaveInterval(e){if(this._autosaveInterval!==e){const t=this._autosaveInterval;this._autosaveInterval=e,this._contexts.forEach((t=>{const s=y.saveHandlerProperty.get(t);s&&(s.saveInterval=e||120)})),this._stateChanged.emit({name:"autosaveInterval",oldValue:t,newValue:e})}}get confirmClosingDocument(){return this._widgetManager.confirmClosingDocument}set confirmClosingDocument(e){if(this._widgetManager.confirmClosingDocument!==e){const t=this._widgetManager.confirmClosingDocument;this._widgetManager.confirmClosingDocument=e,this._stateChanged.emit({name:"confirmClosingDocument",oldValue:t,newValue:e})}}get lastModifiedCheckMargin(){return this._lastModifiedCheckMargin}set lastModifiedCheckMargin(e){if(this._lastModifiedCheckMargin!==e){const t=this._lastModifiedCheckMargin;this._lastModifiedCheckMargin=e,this._contexts.forEach((t=>{t.lastModifiedCheckMargin=e})),this._stateChanged.emit({name:"lastModifiedCheckMargin",oldValue:t,newValue:e})}}get renameUntitledFileOnSave(){return this._renameUntitledFileOnSave}set renameUntitledFileOnSave(e){if(this._renameUntitledFileOnSave!==e){const t=this._renameUntitledFileOnSave;this._renameUntitledFileOnSave=e,this._stateChanged.emit({name:"renameUntitledFileOnSave",oldValue:t,newValue:e})}}get stateChanged(){return this._stateChanged}get isDisposed(){return this._isDisposed}dispose(){this.isDisposed||(this._isDisposed=!0,v.Signal.clearData(this),this._contexts.forEach((e=>this._widgetManager.closeWidgets(e))),this._widgetManager.dispose(),this._contexts.length=0)}cloneWidget(e){return this._widgetManager.cloneWidget(e)}closeAll(){return Promise.all(this._contexts.map((e=>this._widgetManager.closeWidgets(e)))).then((()=>{}))}closeFile(e){const t=this._contextsForPath(e).map((e=>this._widgetManager.closeWidgets(e)));return Promise.all(t).then((e=>{}))}contextForWidget(e){return this._widgetManager.contextForWidget(e)}copy(e,t){return this.services.contents.copy(e,t)}createNew(e,t="default",s){return this._createOrOpenDocument("create",e,t,s)}deleteFile(e){return this.services.sessions.stopIfNeeded(e).then((()=>this.services.contents.delete(e))).then((()=>(this._contextsForPath(e).forEach((e=>this._widgetManager.deleteWidgets(e))),Promise.resolve(void 0))))}duplicate(e){const t=a.PathExt.dirname(e);return this.services.contents.copy(e,t)}findWidget(e,t="default"){const s=a.PathExt.normalize(e);let n=[t];if("default"===t){const e=this.registry.defaultWidgetFactory(s);if(!e)return;n=[e.name]}else null===t&&(n=this.registry.preferredWidgetFactories(s).map((e=>e.name)));for(const e of this._contextsForPath(s))for(const t of n)if(null!==t){const s=this._widgetManager.findWidget(e,t);if(s)return s}}newUntitled(e){return"file"===e.type&&(e.ext=e.ext||".txt"),this.services.contents.newUntitled(e)}open(e,t="default",s,n){return this._createOrOpenDocument("open",e,t,s,n)}openOrReveal(e,t="default",s,n){const i=this.findWidget(e,t);return i?(this._opener.open(i,{type:t,...n}),i):this.open(e,t,s,null!=n?n:{})}overwrite(e,t){const s=`${t}.${m.UUID.uuid4()}`,n=()=>this.rename(s,t);return this.rename(e,s).then((()=>this.deleteFile(t))).then(n,n)}rename(e,t){return this.services.contents.rename(e,t)}_findContext(e,t){const s=this.services.contents.normalize(e);return(0,u.find)(this._contexts,(e=>e.path===s&&e.factoryName===t))}_contextsForPath(e){const t=this.services.contents.normalize(e);return this._contexts.filter((e=>e.path===t))}_createContext(e,t,s){const n=new _.Context({opener:(e,t)=>{this._widgetManager.adoptWidget(n,e),this._opener.open(e,t)},manager:this.services,factory:t,path:e,kernelPreference:s,setBusy:this._setBusy,sessionDialogs:this._dialogs,lastModifiedCheckMargin:this._lastModifiedCheckMargin,translator:this.translator}),i=new f({context:n,isConnectedCallback:this._isConnectedCallback,saveInterval:this.autosaveInterval});return y.saveHandlerProperty.set(n,i),n.ready.then((()=>{this.autosave&&i.start()})),n.disposed.connect(this._onContextDisposed,this),this._contexts.push(n),n}_onContextDisposed(e){u.ArrayExt.removeFirstOf(this._contexts,e)}_widgetFactoryFor(e,t){const{registry:s}=this;if("default"===t){const n=s.defaultWidgetFactory(e);if(!n)return;t=n.name}return s.getWidgetFactory(t)}_createOrOpenDocument(e,t,s="default",n,i){const a=this._widgetFactoryFor(t,s);if(!a)return;const o=a.modelName||"text",r=this.registry.getModelFactory(o);if(!r)return;const c=this.registry.getKernelPreference(t,a.name,n);let l,h=Promise.resolve(void 0);if("open"===e)l=this._findContext(t,r.name)||null,l||(l=this._createContext(t,r,c),h=this._when.then((()=>l.initialize(!1))));else{if("create"!==e)throw new Error(`Invalid argument 'which': ${e}`);l=this._createContext(t,r,c),h=this._when.then((()=>l.initialize(!0)))}const d=this._widgetManager.createWidget(a,l);return this._opener.open(d,{type:a.name,...i}),h.catch((e=>{console.error(`Failed to initialize the context with '${r.name}' for ${t}`,e),d.close()})),d}_onActivateRequested(e,t){this._activateRequested.emit(t)}_onWidgetStateChanged(e,t){"confirmClosingDocument"===t.name&&this._stateChanged.emit(t)}}!function(e){e.saveHandlerProperty=new p.AttachedProperty({name:"saveHandler",create:()=>{}})}(y||(y={}));var P=s(71098),b=s(35613),R=s(78156),S=s.n(R);function T(e){return S().createElement(P.TextItem,{source:e.name,title:e.fullPath})}class F extends b.VDomRenderer{constructor(e){super(new F.Model(e.docManager)),this.node.title=this.model.path}render(){return S().createElement(T,{fullPath:this.model.path,name:this.model.name})}}function k(e){return S().createElement(P.TextItem,{source:e.fileStatus})}!function(e){class t extends b.VDomModel{constructor(e){super(),this._onTitleChange=e=>{const t=this._getAllState();this._name=e.label,this._triggerChange(t,this._getAllState())},this._onPathChange=(e,t)=>{const s=this._getAllState();this._path=t,this._name=a.PathExt.basename(t),this._triggerChange(s,this._getAllState())},this._path="",this._name="",this._widget=null,this._docManager=e}get path(){return this._path}get name(){return this._name}get widget(){return this._widget}set widget(e){const t=this._widget;if(null!==t){const e=this._docManager.contextForWidget(t);e?e.pathChanged.disconnect(this._onPathChange):t.title.changed.disconnect(this._onTitleChange)}const s=this._getAllState();if(this._widget=e,null===this._widget)this._path="",this._name="";else{const e=this._docManager.contextForWidget(this._widget);e?(this._path=e.path,this._name=a.PathExt.basename(e.path),e.pathChanged.connect(this._onPathChange)):(this._path="",this._name=this._widget.title.label,this._widget.title.changed.connect(this._onTitleChange))}this._triggerChange(s,this._getAllState())}_getAllState(){return[this._path,this._name]}_triggerChange(e,t){e[0]===t[0]&&e[1]===t[1]||this.stateChanged.emit(void 0)}}e.Model=t}(F||(F={}));class W extends b.VDomRenderer{constructor(e){super(new W.Model(e.docManager));const t=(e.translator||o.nullTranslator).load("jupyterlab");this._statusMap={completed:t.__("Saving completed"),started:t.__("Saving started"),failed:t.__("Saving failed")}}render(){return null===this.model||null===this.model.status?null:S().createElement(k,{fileStatus:this._statusMap[this.model.status]})}}!function(e){class t extends b.VDomModel{constructor(e){super(),this._onStatusChange=(e,t)=>{this._status=t,"completed"===this._status?(setTimeout((()=>{this._status=null,this.stateChanged.emit(void 0)}),2e3),this.stateChanged.emit(void 0)):this.stateChanged.emit(void 0)},this._status=null,this._widget=null,this._status=null,this.widget=null,this._docManager=e}get status(){return this._status}get widget(){return this._widget}set widget(e){var t,s;const n=this._widget;if(null!==n){const e=this._docManager.contextForWidget(n);e?e.saveState.disconnect(this._onStatusChange):(null===(t=this._widget.content)||void 0===t?void 0:t.saveStateChanged)&&this._widget.content.saveStateChanged.disconnect(this._onStatusChange)}if(this._widget=e,null===this._widget)this._status=null;else{const e=this._docManager.contextForWidget(this._widget);e?e.saveState.connect(this._onStatusChange):(null===(s=this._widget.content)||void 0===s?void 0:s.saveStateChanged)&&this._widget.content.saveStateChanged.connect(this._onStatusChange)}}}e.Model=t}(W||(W={}));const A=new m.Token("@jupyterlab/docmanager:IDocumentManager","A service for the manager for all\n documents used by the application. Use this if you want to open and close documents,\n create and delete files, and otherwise interact with the file system."),E=new m.Token("@jupyterlab/docmanager:IDocumentWidgetOpener","A service to open a widget."),I=new m.Token("@jupyterlab/docmanager:IRecentsManager","A service providing information about recently opened and closed documents");var O,B=s(97934);class N{constructor(e){this._recentsChanged=new v.Signal(this),this._recents={opened:[],closed:[]},this._isDisposed=!1,this._maxRecentsLength=10,this._saveDebouncer=new B.Debouncer(this._save.bind(this),500),this._stateDB=e.stateDB,this._contentsManager=e.contents,this.updateRootDir(),this._loadRecents().catch((e=>{console.error(`Failed to load recent list from state:\n${e}`)}))}get isDisposed(){return this._isDisposed}get recentlyOpened(){return(this._recents.opened||[]).filter((e=>e.root===this._serverRoot))}get recentlyClosed(){return(this._recents.closed||[]).filter((e=>e.root===this._serverRoot))}get changed(){return this._recentsChanged}get maximalRecentsLength(){return this._maxRecentsLength}set maximalRecentsLength(e){this._maxRecentsLength=Math.round(Math.max(1,e));let t=!1;for(const e of["opened","closed"])this._recents[e].length>this._maxRecentsLength&&(this._recents[e].length=this._maxRecentsLength,t=!0);t&&this._recentsChanged.emit(void 0)}dispose(){this.isDisposed||(this._isDisposed=!0,v.Signal.clearData(this),this._saveDebouncer.dispose())}addRecent(e,t){const s={...e,root:this._serverRoot},n=this._recents[t],i=n.findIndex((t=>t.path===e.path));i>=0&&n.splice(i,1),n.unshift(s),this._setRecents(n,t),this._recentsChanged.emit(void 0)}clearRecents(){this._setRecents([],"opened"),this._setRecents([],"closed"),this._recentsChanged.emit(void 0)}removeRecent(e,t){this._removeRecent(e.path,[t])}async validate(e){const t=await this._isValid(e);return t||this._removeRecent(e.path),t}updateRootDir(){this._serverRoot=a.PageConfig.getOption("serverRoot")}_removeRecent(e,t=["opened","closed"]){let s=!1;for(const n of t){const t=this._recents[n],i=t.filter((t=>e!==t.path));t.length!==i.length&&(this._setRecents(i,n),s=!0)}s&&this._recentsChanged.emit(void 0)}async _isValid(e){var t;try{await this._contentsManager.get(e.path,{content:!1})}catch(e){if(404===(null===(t=e.response)||void 0===t?void 0:t.status))return!1}return!0}_setRecents(e,t){this._recents[t]=e.slice(0,this.maximalRecentsLength).sort(((e,t)=>e.root===t.root?0:e.root!==this._serverRoot?1:-1)),this._saveDebouncer.invoke().catch(console.warn)}async _loadRecents(){const e=await this._stateDB.fetch(O.stateDBKey)||{opened:[],closed:[]},t=[...e.opened,...e.closed],s=new Set(await this._getInvalidPaths(t));for(const t of["opened","closed"])this._setRecents(e[t].filter((e=>!s.has(e.path))),t);this._recentsChanged.emit(void 0)}async _getInvalidPaths(e){return(await Promise.all(e.map((async e=>await this._isValid(e)?null:e.path)))).filter((e=>"string"==typeof e))}async _save(){try{await this._stateDB.save(O.stateDBKey,this._recents)}catch(e){console.log("Saving recents failed",e)}}}!function(e){e.stateDBKey="docmanager:recents"}(O||(O={}))}}]); |