(self.webpackChunkjupyterlab_nbsafety=self.webpackChunkjupyterlab_nbsafety||[]).push([[568],{568:(e,t,s)=>{"use strict";s.r(t),s.d(t,{default:()=>E});var n=s(841),o=s(50);const l={id:"jupyterlab-nbsafety",requires:[n.ILayoutRestorer,o.INotebookTracker],autoStart:!0,activate:(e,t,s)=>{s.widgetAdded.connect(((e,t)=>{const s=t.sessionContext;s.ready.then((()=>{L(t.content,-1);let e=p(s.session.kernel,t.content);s.kernelChanged.connect((()=>{L(t.content,-1),e(),e=p(s.session.kernel,t.content)}));let n=!1;s.statusChanged.connect(((s,o)=>{"restarting"!==o&&"autorestarting"!==o||(n=!0),"idle"!==o&&"busy"!==o||!n||(n=!1,s.ready.then((()=>{L(t.content,-1),e(),e=p(s.session.kernel,t.content)})))}))}))}))}},d="stale-cell",a="fresh-cell",c="refresher-cell",i="refresher-input-cell",r="linked-stale",m="linked-refresher",u=new Event("cleanup"),v=e=>e.children.item(1).firstElementChild,f=e=>e.children.item(2).firstElementChild,h=(e,t,s)=>{const n=()=>{e.removeEventListener(t,s),e.removeEventListener("cleanup",n)};e.addEventListener(t,s),e.addEventListener("cleanup",n)},_=(e,t,s,n,o)=>{h(e,s,(()=>{t.firstElementChild.classList[n](o)}))},C=(e,t)=>{_(v(e),f(e),"mouseover","add",r),_(v(e),f(e),"mouseout","remove",r),_(f(e),v(e),"mouseover","add",t),_(f(e),v(e),"mouseout","remove",t)},L=(e,t)=>{e.widgets.forEach(((e,s)=>{if(s<t)return;e.node.classList.remove(d),e.node.classList.remove(c),e.node.classList.remove(a),e.node.classList.remove(i);const n=v(e.node);null!==n&&(n.firstElementChild.classList.remove(r),n.firstElementChild.classList.remove(m),n.dispatchEvent(u));const o=f(e.node);null!==o&&(o.firstElementChild.classList.remove(r),o.firstElementChild.classList.remove(m),o.dispatchEvent(u))}))},g=(e,t,s,n,o,l,d)=>{const a=()=>{for(const e of t){let t=m;d.indexOf(e)>-1&&(t=r),n(s[e]).firstElementChild.classList[l](t)}};e.addEventListener(o,a),h(e,o,a)},p=(e,t)=>{const s=e.createComm("nbsafety");let n=!1;const o=(e,l)=>{if(n)return void e.stateChanged.disconnect(o);if("executionCount"!==l.name||null===l.newValue)return;const d={},c={};t.widgets.forEach(((t,s)=>{d[t.model.id]=t.model.value.text,c[t.model.id]=s,t.model.id===e.id&&(t.node.classList.remove(a),t.node.classList.remove(i))}));const r={type:"cell_freshness",executed_cell_id:e.id,content_by_cell_id:d,order_index_by_cell_id:c};s.send(r)},l=e=>{let n=-1;t.widgets.forEach(((t,s)=>{t.model.id===e.id&&(n=s)}));const o={type:"change_active_cell",active_cell_id:e.id,active_cell_order_idx:n};s.send(o)},u=(e,s)=>{if(n)return void e.stateChanged.disconnect(u);if("activeCellIndex"!==s.name||e!==t)return;const d=e.model.cells.get(s.oldValue);null!==d&&d.stateChanged.disconnect(o,d.stateChanged);const a=e.model.cells.get(s.newValue);null!==a&&(a.stateChanged.connect(o),l(a))};return t.stateChanged.connect(u),s.onMsg=e=>{if(!n)if("establish"===e.content.data.type)t.activeCell.model.stateChanged.connect(o),l(t.activeCell.model);else if("cell_freshness"===e.content.data.type){const s=e.content.data.stale_cells,n=e.content.data.fresh_cells,o=e.content.data.stale_links,l=e.content.data.refresher_links,u=e.content.data.last_cell_exec_position_idx,h={},_={};L(t,u),t.widgets.forEach(((e,t)=>{h[e.model.id]=e.node,_[e.model.id]=t}));for(const[e,t]of Object.entries(h))_[e]<u||(s.indexOf(e)>-1?(t.classList.add(d),t.classList.add(a),t.classList.remove(i),C(t,r)):n.indexOf(e)>-1&&(t.classList.add(i),t.classList.add(a),C(t,m)),o.hasOwnProperty(e)&&(g(v(t),o[e],h,v,"mouseover","add",s),g(f(t),o[e],h,v,"mouseover","add",s),g(v(t),o[e],h,v,"mouseout","remove",s),g(f(t),o[e],h,v,"mouseout","remove",s)),l.hasOwnProperty(e)&&(-1===s.indexOf(e)&&(t.classList.add(c),t.classList.add(a)),g(v(t),l[e],h,v,"mouseover","add",s),g(v(t),l[e],h,f,"mouseover","add",s),g(v(t),l[e],h,v,"mouseout","remove",s),g(v(t),l[e],h,f,"mouseout","remove",s)))}},s.open({}),()=>{n=!0}},E=l}}]);