"use strict";(self.webpackChunkwordslab_notebooks_extension=self.webpackChunkwordslab_notebooks_extension||[]).push([[509],{509:(e,o,t)=>{t.r(o),t.d(o,{default:()=>s});var n=t(766);const s={id:"wordslab-notebooks-extension:plugin",description:"JupyterLab extension for wordslab-notebooks",autoStart:!0,requires:[n.INotebookTracker],activate:(e,o)=>{console.log("Wordslab notebooks extension activated");const t=new Map;n.NotebookActions.executionScheduled.connect((e,n)=>{const{notebook:s,cell:l}=n,d=o.find(e=>(null==e?void 0:e.content)===s);if(!d)return;const a=d.sessionContext.path,c=l.model.id;t.has(a)||t.set(a,[]),t.get(a).push(c),console.log(`Cell ${c} queued for execution in ${a}. Queue:`,t.get(a));const i=()=>{if(null!==l.model.executionCount){const e=t.get(a);if(e){const o=e.shift();console.log(`Cell ${o} finished in ${a}. Queue:`,e)}l.model.stateChanged.disconnect(i)}};l.model.stateChanged.connect(i)});const s=new Set,l=e=>{const o=e.sessionContext;if(!o)return;const n=()=>{var n;const l=null===(n=o.session)||void 0===n?void 0:n.kernel;l&&!s.has(l.id)&&(s.add(l.id),l.registerCommTarget("wordslab_notebook_comm",(n,s)=>{console.log("Comm opened:",{commId:n.commId,targetName:s.content.target_name,openMsgData:s.content.data,notebookPath:o.path}),n.onMsg=s=>{var l,d;if(console.log("Comm message received:",{commId:n.commId,msgData:s.content.data}),"get_notebook_data"===s.content.data.request){const s=o.path,a=t.get(s),c=a&&a.length>0?a[0]:void 0,i=null===(l=e.model)||void 0===l?void 0:l.toJSON();n.send({notebook:i,cell_id:c}),console.log("Sent notebook data:",{notebookPath:s,cellId:c,cellCount:null===(d=null==i?void 0:i.cells)||void 0===d?void 0:d.length})}}}),console.log(`Comm target registered for kernel ${l.id} (${o.path})`))};o.kernelChanged.connect((e,o)=>{o.oldValue&&(s.delete(o.oldValue.id),console.log(`Kernel ${o.oldValue.id} removed from registry`)),o.newValue&&n()}),o.ready.then(()=>n())};o.forEach(e=>l(e)),o.widgetAdded.connect((e,o)=>l(o))}}}}]);