"use strict";(self.webpackChunkpep723widget=self.webpackChunkpep723widget||[]).push([[675],{675:(e,t,n)=>{n.r(t),n.d(t,{default:()=>h});var o=n(679),a=n(805),s=n(480),i=n(256),c=n(708),l=n(955);class r extends i.Widget{constructor(e){super(),this._context=e,this.addClass("pep723-notebook-widget"),this.title.label="PEP 723 Viewer",this.title.closable=!0,this.title.iconClass="jp-NotebookIcon",this._createContent(),this._context.model.contentChanged.connect(this._onContentChanged,this)}_createContent(){const e=document.createElement("div");e.className="pep723-container";const t=document.createElement("h2");t.textContent="PEP 723 Inline Script Metadata Viewer",e.appendChild(t);const n=document.createElement("div");n.className="notebook-info",n.innerHTML=`\n      <p><strong>Notebook:</strong> ${this._context.path}</p>\n      <p><strong>Cells:</strong> ${this._context.model.cells.length}</p>\n    `,e.appendChild(n);const o=document.createElement("div");o.className="metadata-section",this._updateMetadataContent(o),e.appendChild(o),this.node.appendChild(e)}_updateMetadataContent(e){e.innerHTML="<h3>PEP 723 Script Metadata</h3>";const t=this._context.model.cells;let n=!1;for(let o=0;o<t.length;o++){const a=t.get(o);if("code"===a.type){const t=a.sharedModel.getSource(),s=/^#\s*\/\/\/\s*(.*)$/gm,i=[];let c;for(;null!==(c=s.exec(t));)i.push(c);if(i.length>0){n=!0;const t=document.createElement("div");t.className="pep723-cell",t.innerHTML=`\n            <h4>Cell ${o+1}</h4>\n            <pre class="pep723-metadata">${i.map(e=>e[1]).join("\n")}</pre>\n          `,e.appendChild(t)}}}if(!n){const t=document.createElement("p");t.textContent="No PEP 723 script metadata found in this notebook.",t.className="no-metadata",e.appendChild(t)}}_onContentChanged(){const e=this.node.querySelector(".metadata-section");e&&this._updateMetadataContent(e)}dispose(){this._context.model.contentChanged.disconnect(this._onContentChanged,this),super.dispose()}}class d extends s.ABCWidgetFactory{createNewWidget(e){const t=new r(e),n=new s.DocumentWidget({content:t,context:e});return n.title.label=`PEP 723: ${e.localPath}`,n}}const p={id:"pep723widget:plugin",description:"A JupyterLab extension to edit pep723 inline script metadata in notebooks.",autoStart:!0,requires:[a.IDocumentManager],optional:[o.ISettingRegistry],activate:(e,t,n)=>{console.log("JupyterLab extension pep723widget is activated!");const o=new d({name:"pep723-notebook-viewer",label:"PEP 723 Viewer",fileTypes:["notebook"],defaultFor:[],canStartKernel:!1,shutdownOnClose:!1,modelName:"notebook"});t.registry.addWidgetFactory(o),n&&n.load(p.id).then(e=>{console.log("pep723widget settings loaded:",e.composite)}).catch(e=>{console.error("Failed to load settings for pep723widget.",e)}),async function(e="",t={}){const n=l.ServerConnection.makeSettings(),o=c.URLExt.join(n.baseUrl,"pep723widget",e);let a;try{a=await l.ServerConnection.makeRequest(o,t,n)}catch(e){throw new l.ServerConnection.NetworkError(e)}let s=await a.text();if(s.length>0)try{s=JSON.parse(s)}catch(e){console.log("Not a JSON response body.",a)}if(!a.ok)throw new l.ServerConnection.ResponseError(a,s.message||s);return s}("get-example").then(e=>{console.log(e)}).catch(e=>{console.error(`The pep723widget server extension appears to be missing.\n${e}`)})}},h=p}}]);