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