|
"use strict";(self.webpackChunk_JUPYTERLAB_CORE_OUTPUT=self.webpackChunk_JUPYTERLAB_CORE_OUTPUT||[]).push([[1809],{1809:(t,e,s)=>{s.r(e),s.d(e,{IRunningSessionManagers:()=>C,IRunningSessionSidebar:()=>y,RunningSessionManagers:()=>I,RunningSessions:()=>L,SearchableSessions:()=>D,SearchableSessionsList:()=>B});var n=s(53312),i=s(12030),a=s(35613),o=s(20998),l=s(2549),r=s(18395),d=s(81997),h=s(63485),c=s(78156),u=s.n(c);const g="jp-RunningSessions",p="jp-RunningSessions-sectionList",_="jp-RunningSessions-item",m="jp-RunningSessions-itemLabel",w="jp-RunningSessions-itemDetail",b="jp-RunningSessions-itemShutdown",f="jp-RunningSessions-caret",S="jp-RunningSessions-icon",v="jp-running-sessions",C=new o.Token("@jupyterlab/running:IRunningSessionManagers","A service to add running session managers."),y=new o.Token("@jupyterlab/running:IRunningSessionsSidebar","A token allowing to modify the running sessions sidebar.");class I{constructor(){this._added=new d.Signal(this),this._managers=[]}get added(){return this._added}add(t){return this._managers.push(t),this._added.emit(t),new l.DisposableDelegate((()=>{const e=this._managers.indexOf(t);e>-1&&this._managers.splice(e,1)}))}items(){return this._managers}}function T(t){var e,s;const{runningItem:n}=t,o=[_],l=null===(e=n.detail)||void 0===e?void 0:e.call(n),r=n.icon(),d=n.labelTitle?n.labelTitle():"",h=t.translator||i.nullTranslator,c=h.load("jupyterlab");let g=!1;const p=t.shutdownItemIcon||a.closeIcon,v=null!==(s="function"==typeof t.shutdownLabel?t.shutdownLabel(n):t.shutdownLabel)&&void 0!==s?s:c.__("Shut Down"),C=n.children,[y,I]=u().useState(!1),T=!!(null==C?void 0:C.length),E=T?()=>!g&&I(!y):void 0;return t.collapseToggled.connect(((t,e)=>I(e))),n.className&&o.push(n.className),t.child&&o.push("jp-mod-running-child"),t.child&&!C&&o.push("jp-mod-running-leaf"),u().createElement(u().Fragment,null,u().createElement("li",null,u().createElement("div",{className:o.join(" "),onClick:E,"data-context":n.context||""},T&&(y?u().createElement(a.caretRightIcon.react,{tag:"span",className:f}):u().createElement(a.caretDownIcon.react,{tag:"span",className:f})),r?"string"==typeof r?u().createElement("img",{src:r,className:S}):u().createElement(r.react,{tag:"span",className:S}):void 0,u().createElement("span",{className:m,title:d,onClick:n.open&&(()=>n.open())},n.label()),l&&u().createElement("span",{className:w},l),n.shutdown&&u().createElement(a.ToolbarButtonComponent,{className:b,icon:p,onClick:()=>{var t;g=!0,null===(t=n.shutdown)||void 0===t||t.call(n)},tooltip:v})),T&&!y&&u().createElement(j,{child:!0,runningItems:C,shutdownItemIcon:p,translator:h,collapseToggled:t.collapseToggled})))}function j(t){const e=t.filter,s=e?t.runningItems.map((t=>({item:t,score:e(t)}))).filter((({score:t})=>null!==t)).sort(((t,e)=>t.score.score-e.score.score)).map((({item:t})=>t)):t.runningItems;return u().createElement("ul",{className:p},s.map(((e,s)=>u().createElement(T,{child:t.child,key:s,runningItem:e,shutdownLabel:t.shutdownLabel,shutdownItemIcon:t.shutdownItemIcon,translator:t.translator,collapseToggled:t.collapseToggled}))))}class E extends a.ReactWidget{constructor(t){super(),this._filterFn=t=>({score:0}),this._filterChanged=new d.Signal(this),this.filter=this.filter.bind(this),this._updateFilter=this._updateFilter.bind(this),this._trans=t.load("jupyterlab"),this.addClass("jp-SearchableSessions-filter")}get filterChanged(){return this._filterChanged}render(){return u().createElement(a.FilterBox,{placeholder:this._trans.__("Search"),updateFilter:this._updateFilter,useFuzzyFilter:!1,caseSensitive:!1})}filter(t){var e;const s=[this._getTextContent(t.label())];for(const n of null!==(e=t.children)&&void 0!==e?e:[])s.push(this._getTextContent(n.label()));return this._filterFn(s.join(" "))}_getTextContent(t){return"string"==typeof t?t:"number"==typeof t||"boolean"==typeof t?""+t:Array.isArray(t)?t.map((t=>this._getTextContent(t))).join(" "):t&&(0,c.isValidElement)(t)?t.props.children.map((t=>this._getTextContent(t))).join(" "):""}_updateFilter(t){this._filterFn=t,this._filterChanged.emit()}}class x extends a.ReactWidget{constructor(t){super(),this._options=t,this._update=new d.Signal(this),t.manager.runningChanged.connect(this._emitUpdate,this),t.filterProvider&&t.filterProvider.filterChanged.connect(this._emitUpdate,this)}dispose(){d.Signal.clearData(this),super.dispose()}onBeforeShow(t){super.onBeforeShow(t),this._update.emit()}render(){const t=this._options;let e=!0;return u().createElement(a.UseSignal,{signal:this._update},(()=>{var s;return e?e=!1:t.runningItems=t.manager.running(),u().createElement("div",{className:"jp-RunningSessions-sectionContainer"},u().createElement(j,{runningItems:t.runningItems,shutdownLabel:t.manager.shutdownLabel,shutdownItemIcon:t.manager.shutdownItemIcon,filter:null===(s=t.filterProvider)||void 0===s?void 0:s.filter,translator:t.translator,collapseToggled:t.collapseToggled}))}))}_isAnyHidden(){let t=this.isHidden;if(t)return t;let e=this.parent;for(;null!=e;){if(e.isHidden){t=!0;break}e=e.parent}return t}_emitUpdate(){this._isAnyHidden()||this._update.emit()}}class A extends a.PanelWithToolbar{constructor(t){super(),this._buttons=null,this._listView=!1,this._collapseToggled=new d.Signal(this),this._viewChanged=new d.Signal(this),this._manager=t.manager,this._filterProvider=t.filterProvider;const e=t.translator||i.nullTranslator;this._trans=e.load("jupyterlab"),this.addClass("jp-RunningSessions-section"),this.title.label=t.manager.name,this._manager.runningChanged.connect(this._onListChanged,this),t.filterProvider&&t.filterProvider.filterChanged.connect(this._onListChanged,this),this._updateEmptyClass();let s=t.manager.running();!1!==t.showToolbar&&this._initializeToolbar(s),this.addWidget(new x({runningItems:s,collapseToggled:this._collapseToggled,...t}))}toggleListView(t){const e=void 0!==t?t:!this._listView;this._listView=e,this._buttons&&(this._buttons["switch-view"].pressed=e),this._collapseToggled.emit(!1),this.toggleClass("jp-mod-running-list-view",e),this._updateButtons(),this._viewChanged.emit({mode:e?"list":"tree"})}dispose(){this.isDisposed||(d.Signal.clearData(this),super.dispose())}get _shutdownAllLabel(){return this._manager.shutdownAllLabel||this._trans.__("Shut Down All")}_initializeToolbar(t){const e=t.length>0,s=this._shutdownAllLabel,i=`${s}?`,o=this._manager.shutdownAllConfirmationText||`${s} ${this._manager.name}`,l=new a.ToolbarButton({label:s,className:"jp-RunningSessions-shutdownAll"+(e?"":" jp-mod-disabled"),enabled:e,onClick:(()=>{(0,n.showDialog)({title:i,body:o,buttons:[n.Dialog.cancelButton(),n.Dialog.warnButton({label:s})]}).then((t=>{t.button.accept&&this._manager.shutdownAll()}))}).bind(this)}),r=new a.ToolbarButton({className:"jp-RunningSessions-viewButton",enabled:e,icon:a.tableRowsIcon,pressedIcon:a.treeViewIcon,onClick:()=>this.toggleListView(),tooltip:this._trans.__("Switch to List View"),pressedTooltip:this._trans.__("Switch to Tree View")}),d=new a.ToolbarButton({className:"jp-RunningSessions-collapseButton",enabled:e,icon:a.collapseAllIcon,pressedIcon:a.expandAllIcon,onClick:()=>{const t=!d.pressed;this._collapseToggled.emit(t),d.pressed=t},tooltip:this._trans.__("Collapse All"),pressedTooltip:this._trans.__("Expand All")});this._buttons={"switch-view":r,"collapse-expand":d,"shutdown-all":l},this._updateButtons(),this._manager.runningChanged.connect(this._updateButtons,this);for(const t of["collapse-expand","switch-view","shutdown-all"])this.toolbar.addItem(t,this._buttons[t]);this.toolbar.addClass("jp-RunningSessions-toolbar")}_onListChanged(){this._updateButtons(),this._updateEmptyClass()}_updateEmptyClass(){this._filterProvider&&(0===this._manager.running().filter(this._filterProvider.filter).length?this.node.classList.toggle("jp-mod-empty",!0):this.node.classList.toggle("jp-mod-empty",!1))}get viewChanged(){return this._viewChanged}_updateButtons(){if(!this._buttons)return;let t=this._manager.running();const e=t.length>0,s=0!==t.filter((t=>t.children)).length,n=s&&!this._buttons["switch-view"].pressed;this._buttons["switch-view"].node.style.display=s?"block":"none",this._buttons["collapse-expand"].node.style.display=n?"block":"none",this._buttons["collapse-expand"].enabled=e,this._buttons["switch-view"].enabled=e,this._buttons["shutdown-all"].enabled=e}}class L extends a.SidePanel{constructor(t,e,s){super(),this.managers=t,this._stateDB=null!=s?s:null,this.translator=null!=e?e:i.nullTranslator;const n=this.translator.load("jupyterlab");this.addClass(g),this.toolbar.addItem("refresh",new a.ToolbarButton({tooltip:n.__("Refresh List"),icon:a.refreshIcon,onClick:()=>t.items().forEach((t=>t.refreshRunning()))})),t.items().forEach((e=>this.addSection(t,e))),t.added.connect(this.addSection,this)}dispose(){this.isDisposed||(this.managers.added.disconnect(this.addSection,this),super.dispose())}async addSection(t,e){const s=new A({manager:e,translator:this.translator});this.addWidget(s);const n=(await this._getState()).listViewSections,i=e.name;n&&n.includes(i)&&s.toggleListView(!0),s.viewChanged.connect((async(t,e)=>{await this._updateState(i,e.mode)}))}async _updateState(t,e){var s;let n=null!==(s=(await this._getState()).listViewSections)&&void 0!==s?s:[];"list"!==e||n.includes(t)?n=n.filter((e=>e!==t)):n.push(t);const i={listViewSections:n};this._stateDB&&await this._stateDB.save(v,i)}async _getState(){var t;return this._stateDB&&null!==(t=await this._stateDB.fetch(v))&&void 0!==t?t:{}}}class R extends A{constructor(t){super(t);const e=document.createElement("h3");e.className="jp-SearchableSessions-title";const s=e.appendChild(document.createElement("span"));s.className="jp-SearchableSessions-titleLabel",s.textContent=this.title.label,this.node.insertAdjacentElement("afterbegin",e)}}class k extends h.Widget{constructor(t){super();const e=t.load("jupyterlab");this.addClass("jp-SearchableSessions-emptyIndicator"),this.node.textContent=e.__("No matches")}}class D extends h.Panel{constructor(t,e){super(),this._activeIndex=0,this._translator=null!=e?e:i.nullTranslator,this.addClass(g),this.addClass("jp-SearchableSessions"),this._filterWidget=new E(this._translator),this.addWidget(this._filterWidget),this._list=new B(t,this._filterWidget,e),this.addWidget(this._list),this._filterWidget.filterChanged.connect((()=>{this._activeIndex=0,this._updateActive(0)}),this)}dispose(){this.isDisposed||(d.Signal.clearData(this),super.dispose())}getValue(){const t=[...this.node.querySelectorAll("."+m)];t[Math.min(Math.max(this._activeIndex,0),t.length-1)].click()}handleEvent(t){"keydown"===t.type&&this._evtKeydown(t)}onAfterAttach(t){this._forceFocusInput(),this.node.addEventListener("keydown",this),setTimeout((()=>{this._updateActive(0)}),0)}onAfterDetach(t){this.node.removeEventListener("keydown",this)}_forceFocusInput(){var t;null===(t=this._filterWidget.renderPromise)||void 0===t||t.then((()=>{var t;const e=this._filterWidget.node.querySelector("jp-search"),s=null===(t=null==e?void 0:e.shadowRoot)||void 0===t?void 0:t.querySelector("input");s?s.focus():console.warn("Input element not found, cannot focus")})).catch(console.warn)}_evtKeydown(t){if("ArrowDown"===t.key||"ArrowUp"===t.key){const e="ArrowDown"===t.key?1:-1;this._updateActive(e)&&t.preventDefault()}}_updateActive(t){const e=[...this.node.querySelectorAll("."+_)].filter((t=>t.checkVisibility()));if(!e.length)return!1;for(const t of e)t.classList.contains("jp-mod-active")&&t.classList.toggle("jp-mod-active",!1);const s=this._activeIndex;let n=null;return n=-1===s?1===t?0:e.length-1:Math.min(Math.max(s+t,0),e.length-1),null!==n&&(e[n].classList.add("jp-mod-active"),r.ElementExt.scrollIntoViewIfNeeded(this._list.node,e[n]),this._activeIndex=n,!0)}}class B extends h.Panel{constructor(t,e,s){super(),this._managers=t,this._translator=null!=s?s:i.nullTranslator,this._filterWidget=e,this.addClass("jp-SearchableSessions-list"),this._emptyIndicator=new k(this._translator),this.addWidget(this._emptyIndicator),t.items().forEach((e=>this.addSection(t,e))),t.added.connect(this.addSection,this)}dispose(){this.isDisposed||(this._managers.added.disconnect(this.addSection,this),super.dispose())}addSection(t,e){const s=new R({manager:e,translator:this._translator,showToolbar:!1,filterProvider:this._filterWidget});s.toggleListView(!0),this.addWidget(s),this.addWidget(this._emptyIndicator)}}}}]); |