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