"use strict";(self.webpackChunkjupyterlab_nbsafety=self.webpackChunkjupyterlab_nbsafety||[]).push([[568],{568:(e,t,n)=>{n.r(t),n.d(t,{default:()=>N});var l=n(15),s=n(849);const o="nbsafety",a={id:"jupyterlab-nbsafety",requires:[s.INotebookTracker],autoStart:!0,activate:(e,t)=>{t.widgetAdded.connect(((e,t)=>{const n=t.sessionContext;n.ready.then((()=>{A(t.content),w=t.content.activeCell,p=t.content.activeCell.model.id;let e=()=>{};n.session.kernel.name===o&&(e=M(n,t.content)),n.kernelChanged.connect(((l,s)=>{A(t.content),e(),e=()=>{},null!==s.newValue&&s.newValue.name===o&&(e=M(n,t.content))}));let l=!1;n.statusChanged.connect(((n,s)=>{"restarting"!==s&&"autorestarting"!==s||(l=!0),"idle"!==s&&"busy"!==s||!l||(l=!1,n.ready.then((()=>{A(t.content),e(),e=()=>{},n.session.kernel.name===o&&(e=M(n,t.content))})))}))}))}))}},d="stale-cell",c="fresh-cell",i="refresher-cell",r="refresher-input-cell",u="linked-stale",m="linked-refresher";let h=new Set,f=new Set,v=new Set,C={},_={},w=null,p=null,E={},L={},y=null,g=null,b=null,k=new Set,S=new Set;const x=new Event("cleanup"),j=e=>{if(null==e)return null;const t=e.children.item(1);return null===t?null:t.firstElementChild},D=e=>{if(null==e)return null;const t=e.children.item(2);return null===t?null:t.firstElementChild},O=(e,t,n)=>{const l=()=>{e.removeEventListener(t,n),e.removeEventListener("cleanup",l)};e.addEventListener(t,n),e.addEventListener("cleanup",l)},V=(e,t,n,l,s)=>{null!==e&&null!==t&&O(e,n,(()=>{t.firstElementChild.classList[l](s)}))},P=(e,t)=>{V(j(e),D(e),"mouseover","add",u),V(j(e),D(e),"mouseout","remove",u),V(D(e),j(e),"mouseover","add",t),V(D(e),j(e),"mouseout","remove",t)},q=e=>{E={},L={},e.widgets.forEach(((e,t)=>{E[e.model.id]=e.node,L[e.model.id]=t}))},A=e=>{e.widgets.forEach(((e,t)=>{e.node.classList.remove(d),e.node.classList.remove(i),e.node.classList.remove(c),e.node.classList.remove(r);const n=j(e.node);null!==n&&(n.firstElementChild.classList.remove(u),n.firstElementChild.classList.remove(m),n.dispatchEvent(x));const l=D(e.node);null!==l&&(l.firstElementChild.classList.remove(u),l.firstElementChild.classList.remove(m),l.dispatchEvent(x))}))},I=(e,t,n,l,s,o,a)=>{if(null===e)return;const d=()=>{for(const e of t){let t=m;a.has(e)&&(t=u);const s=l(n[e]);if(null===s||null===s.firstElementChild)return;s.firstElementChild.classList[o](t)}};e.addEventListener(s,d),O(e,s,d)},M=(e,t)=>{const n=e.session.kernel.createComm("nbsafety");let s=!1;const o=(a,d)=>{if(s)return void a.stateChanged.disconnect(o);if("executionCount"!==d.name||null===d.newValue)return;const i={};t.widgets.forEach(((e,t)=>{i[e.model.id]=t,e.model.id===a.id&&(e.node.classList.remove(c),e.node.classList.remove(r))}));const u={type:"cell_freshness",executed_cell_id:a.id,order_index_by_cell_id:i};n.send(u).done.then((()=>{null!==y?l.CodeCell.execute(y,e):"reactive"===g&&(v=k,S=new Set,k=new Set,V(t))}))},a=e=>{let l=-1;t.widgets.forEach(((t,n)=>{t.model.id===e.id&&(l=n)}));const s={type:"change_active_cell",active_cell_id:e.id,active_cell_order_idx:l};n.send(s)},L=(e,n)=>{if(t===e)if(s)t.activeCellChanged.disconnect(L);else if(a(n.model),null!==w&&null!==w.model&&(w.model.isDirty?h.add(p):h.delete(p),w.model.stateChanged.disconnect(o,w.model.stateChanged)),w=n,p=n.model.id,null!==w&&null!==w.model&&"code"===w.model.type){if(w.model.stateChanged.connect(o),a(w.model),h.has(p)){const e=w.model;void 0!==e._setDirty&&e._setDirty(!0)}q(t),O(p)}};t.activeCellChanged.connect(L);const x=[{action:"mouseover",update:"add"},{action:"mouseout",update:"remove"}],O=e=>{const t=E[e];f.has(e)?(t.classList.add(d),t.classList.add(c),t.classList.remove(r),P(t,u)):v.has(e)&&(t.classList.add(r),"normal"===g&&(t.classList.add(c),P(t,m))),"reactive"!==g&&(C.hasOwnProperty(e)&&x.forEach((({action:n,update:l})=>{I(j(t),C[e],E,j,n,l,f),I(D(t),C[e],E,j,n,l,f)})),_.hasOwnProperty(e)&&(f.has(e)||(t.classList.add(i),t.classList.add(c)),x.forEach((({action:n,update:l})=>{I(j(t),_[e],E,j,n,l,f),I(j(t),_[e],E,D,n,l,f)}))))},V=e=>{if(A(e),b){q(e);for(const[e]of Object.entries(E))O(e)}};return n.onMsg=e=>{if(!s)if("establish"===e.content.data.type)t.activeCell.model.stateChanged.connect(o),a(t.activeCell.model);else if("cell_freshness"===e.content.data.type){f=new Set(e.content.data.stale_cells),v=new Set(e.content.data.fresh_cells),S=new Set([...S,...e.content.data.new_fresh_cells]),C=e.content.data.stale_links,_=e.content.data.refresher_links,y=null;const n=e.content.data.exec_mode;if(g=n,b=e.content.data.highlights_enabled,"normal"===n)S=new Set,V(t);else if("reactive"===n){k.add(e.content.data.last_executed_cell_id),A(t);let n=!1;t.widgets.forEach((e=>{n||S.has(e.model.id)&&!k.has(e.model.id)&&("code"===e.model.type&&(y=e),n=!0)}))}else console.warn(`Unknown execution mode: ${n}`)}},n.open({}),()=>{s=!0}},N=a}}]);