(self.webpackChunk_gavincyi_jupyterlab_executor=self.webpackChunk_gavincyi_jupyterlab_executor||[]).push([[645],{645:(e,t,n)=>{"use strict";n.r(t),n.d(t,{default:()=>b});var a=n(188),l=n(740),o=n(129),c=n(510),r=n(28),u=n(556),s=n(2);class i{}function d(e,t){const n=document.createElement("div");var a=document.createElement("label");a.textContent="Executor",n.appendChild(a);const l=document.createElement("select");for(const t of e.executors){const e=document.createElement("option");e.text=t.name,e.value=t.command,l.appendChild(e)}var o;return n.appendChild(l),(a=document.createElement("label")).textContent="Path",n.appendChild(a),(o=document.createElement("input")).className="path",o.type="text",o.value=t,o.disabled=!0,n.appendChild(o),(a=document.createElement("label")).textContent="Arugments",n.appendChild(a),(o=document.createElement("input")).className="arguments",o.type="text",o.value="",n.appendChild(o),(a=document.createElement("label")).textContent="Environment variables",n.appendChild(a),(o=document.createElement("input")).className="envs",o.type="text",o.value="",n.appendChild(o),n}class m extends c.Widget{constructor(e,t){super({node:d(t,e)}),this._path="",this._path=e}getValue(){const e=this.node.querySelector("select"),t=this.node.querySelector(".arguments"),n=this.node.querySelector(".envs");var a=e.value;return n.value&&(a=`${n.value} ${a}`),a.replace("{path}",this._path).replace("{args}",t.value)}}const p="@gavincyi/jupyterlab-executor:executor",h="jupyterlab-executor:execute",b={id:p,autoStart:!0,requires:[l.IFileBrowserFactory,o.ISettingRegistry],activate:function(e,t,n){console.log("JupyterLab extension jupyterlab-executor is activated!");const{tracker:l}=t,o=new i;Promise.all([n.load(p),e.restored]).then((([e])=>{o.executors=e.get("executors").composite})),e.commands.addCommand(h,{execute:()=>{const t=l.currentWidget;if(!t)return;const n=t.selectedItems().next().path;!function(e,t,n){(0,r.showDialog)({title:"Execute",buttons:[r.Dialog.createButton({label:"Execute"}),r.Dialog.okButton({label:"Copy Command"}),r.Dialog.cancelButton({label:"Cancel"})],body:new m(t,n)}).then((async t=>{if(t.button.accept)if("Execute"===t.button.label){console.log("Execute the command");const n=new u.TerminalManager,a=await n.startNew(),l=new s.Terminal(a,{initialCommand:`${t.value}`});l.title.closable=!0;const o=new r.MainAreaWidget({content:l});o.id="jupyter-executor",o.title.label="Execute",o.title.closable=!0,o.isAttached||e.shell.add(o,"main"),e.shell.activateById(o.id)}else"Copy Command"===t.button.label?r.Clipboard.copyToSystem(t.value):console.log(`${t.button.label}`);else console.log("Canceled")}))}(e,n,o)},isVisible:()=>{return(e=l.currentWidget)&&1===(0,a.toArray)(e.selectedItems()).length;var e},iconClass:"jp-RunIcon",label:"Execute"}),e.contextMenu.addItem({command:h,selector:".jp-DirListing-item"})}}}}]);