"use strict";(self.webpackChunk_voila_dashboards_widgets_manager7=self.webpackChunk_voila_dashboards_widgets_manager7||[]).push([[496],{7496:(e,t,r)=>{r.r(t),r.d(t,{default:()=>M});var s=r(3487),i=r(9874),o=r(3291),n=r(1041),d=r(7247),a=r(7498),l=r(2456),g=r(7262),u=r(4602),c=r(1247),w=r(6230);class p extends o.WidgetManager{constructor(){super(...arguments),this._loadedFromKernel=new g.PromiseDelegate,this._modelRegistered=new u.Signal(this),this._registeredModels=new Set}register_model(e,t){super.register_model(e,t),this._registeredModels.add(e),this._modelRegistered.emit(e)}get kernel(){var e;return null===(e=this.context.sessionContext.session)||void 0===e?void 0:e.kernel}get registeredModels(){return this._registeredModels}get modelRegistered(){return this._modelRegistered}removeRegisteredModel(e){this._registeredModels.delete(e)}async _loadFromKernel(){await super._loadFromKernel(),this._loadedFromKernel.resolve()}get loadedModelsFromKernel(){return this._loadedFromKernel.promise}async display_view(e,t,r){return r.el&&c.Widget.attach(t.pWidget,r.el),t.el&&(t.el.setAttribute("data-voila-jupyter-widget",""),t.el.addEventListener("jupyterWidgetResize",(e=>{w.MessageLoop.postMessage(t.pWidget,c.Widget.ResizeMessage.UnknownSize)}))),t.pWidget}restoreWidgets(e){return Promise.resolve()}}const m="application/vnd.jupyter.widget-view+json";class h extends o.WidgetRenderer{constructor(e,t){super(e,t),this.voilaManager=t}async renderModel(e){return await this.voilaManager.loadedModelsFromKernel,super.renderModel(e)}}const M=[{id:"@voila-dashboards/voila:widget-manager7",autoStart:!0,requires:[d.IRenderMimeRegistry],provides:s.IJupyterWidgetRegistry,activate:async(e,t)=>{if("Voila"!==e.name)throw Error("The Voila Widget Manager plugin must be activated in a VoilaApp");const d=n.PageConfig.getBaseUrl(),g=n.PageConfig.getOption("kernelId"),u=a.ServerConnection.makeSettings({baseUrl:d}),c=await a.KernelAPI.getKernelModel(g,u);if(!c)return{registerWidget(e){throw Error(`The model for kernel id ${g} does not exist`)}};const w=new l.KernelConnection({model:c,serverSettings:u}),M=new p({sessionContext:{session:{kernel:w,kernelChanged:{connect:()=>{}}},statusChanged:{connect:()=>{}},kernelChanged:{connect:()=>{}},connectionStatusChanged:{connect:()=>{}}},saveState:{connect:()=>{}}},t,{saveState:!1});return e.widgetManager=M,t.removeMimeType(m),t.addFactory({safe:!1,mimeTypes:[m],createRenderer:e=>new h(e,M)},-10),M.register({name:"@jupyter-widgets/controls",version:i.A,exports:()=>new Promise(((e,t)=>{r.e(869).then((t=>{e(r(2376))}).bind(null,r)).catch((e=>{t(e)}))}))}),M.register({name:"@jupyter-widgets/base",version:s.JUPYTER_WIDGETS_VERSION,exports:{WidgetModel:s.WidgetModel,WidgetView:s.WidgetView,DOMWidgetView:s.DOMWidgetView,DOMWidgetModel:s.DOMWidgetModel,LayoutModel:s.LayoutModel,LayoutView:s.LayoutView,StyleModel:s.StyleModel,StyleView:s.StyleView}}),M.register({name:"@jupyter-widgets/output",version:o.output.OUTPUT_WIDGET_VERSION,exports:o.output}),e.started.then((async()=>{await M._loadFromKernel()})),window.addEventListener("beforeunload",(e=>{const t=new FormData,r=document.cookie.match("\\b_xsrf=([^;]*)\\b"),s=r&&r[1]||"";t.append("_xsrf",s),window.navigator.sendBeacon(`${d}voila/api/shutdown/${w.id}`,t),w.dispose()})),{registerWidget:async t=>{(await e.widgetManagerPromise.promise).register(t)}}}}]}}]);