"use strict";(self.webpackChunk_voila_dashboards_widgets_manager8=self.webpackChunk_voila_dashboards_widgets_manager8||[]).push([[496],{7496:(e,r,t)=>{t.r(r),t.d(r,{default:()=>w});var i=t(8889),s=t(7201),d=t(8597),a=t(3251),o=t(2358),n=t(2456),g=t(4602);class l extends s.KernelWidgetManager{constructor(){super(...arguments),this._modelRegistered=new g.Signal(this),this._registeredModels=new Set}register_model(e,r){super.register_model(e,r),this._registeredModels.add(e),this._modelRegistered.emit(e)}get registeredModels(){return this._registeredModels}get modelRegistered(){return this._modelRegistered}removeRegisteredModel(e){this._registeredModels.delete(e)}}const m="application/vnd.jupyter.widget-view+json",w=[{id:"@voila-dashboards/voila:widget-manager8",autoStart:!0,requires:[a.IRenderMimeRegistry],provides:i.IJupyterWidgetRegistry,activate:async(e,r)=>{if("Voila"!==e.name)throw Error("The Voila Widget Manager plugin must be activated in a VoilaApp");const t=d.PageConfig.getBaseUrl(),i=d.PageConfig.getOption("kernelId"),a=o.ServerConnection.makeSettings({baseUrl:t}),g=await o.KernelAPI.getKernelModel(i,a);if(!g)return{registerWidget(e){throw Error(`The model for kernel id ${i} does not exist`)}};const w=new n.KernelConnection({model:g,serverSettings:a}),c=new l(w,r);return e.widgetManager=c,r.removeMimeType(m),r.addFactory({safe:!1,mimeTypes:[m],createRenderer:e=>new s.WidgetRenderer(e,c)},-10),window.addEventListener("beforeunload",(e=>{const r=new FormData,i=document.cookie.match("\\b_xsrf=([^;]*)\\b"),s=i&&i[1]||"";r.append("_xsrf",s),window.navigator.sendBeacon(`${t}voila/api/shutdown/${w.id}`,r),w.dispose()})),{registerWidget:async r=>{(await e.widgetManagerPromise.promise).register(r)}}}}]}}]);