"use strict";(self.rspackChunk_jupyter_collaboration_extension=self.rspackChunk_jupyter_collaboration_extension||[]).push([[44],{5068(e,t,r){var n=r(6758),o=r.n(n),s=r(935),i=r.n(s)()(o());i.push([e.id,`/* -----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|---------------------------------------------------------------------------- */

.jp-timelineSliderWrapper .jp-sliderContainer{
  display: flex;
  align-items: center;
}

.jp-Slider {
  height: 4.5px
}

#jp-slider-status-bar {
  display: flex;
}

.jp-timestampDisplay {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
}

.jp-restoreBtnContainer {
  width: 192px;
}

.jp-ToolbarButtonComponent.jp-restoreBtn {
  cursor: pointer;
  color: var(--jp-layout-color2);
  width: 100%;
  background: var(--jp-accept-color-normal)
}
`,""]),r.d(t,{},{A:i})},935(e){e.exports=function(e){var t=[];return t.toString=function(){return this.map(function(t){var r="",n=void 0!==t[5];return t[4]&&(r+="@supports (".concat(t[4],") {")),t[2]&&(r+="@media ".concat(t[2]," {")),n&&(r+="@layer".concat(t[5].length>0?" ".concat(t[5]):""," {")),r+=e(t),n&&(r+="}"),t[2]&&(r+="}"),t[4]&&(r+="}"),r}).join("")},t.i=function(e,r,n,o,s){"string"==typeof e&&(e=[[null,e,void 0]]);var i={};if(n)for(var a=0;a<this.length;a++){var l=this[a][0];null!=l&&(i[l]=!0)}for(var c=0;c<e.length;c++){var d=[].concat(e[c]);n&&i[d[0]]||(void 0!==s&&(void 0===d[5]||(d[1]="@layer".concat(d[5].length>0?" ".concat(d[5]):""," {").concat(d[1],"}")),d[5]=s),r&&(d[2]&&(d[1]="@media ".concat(d[2]," {").concat(d[1],"}")),d[2]=r),o&&(d[4]?(d[1]="@supports (".concat(d[4],") {").concat(d[1],"}"),d[4]=o):d[4]="".concat(o)),t.push(d))}},t}},6758(e){e.exports=function(e){return e[1]}},2591(e){var t=[];function r(e){for(var r=-1,n=0;n<t.length;n++)if(t[n].identifier===e){r=n;break}return r}function n(e,n){for(var o={},s=[],i=0;i<e.length;i++){var a=e[i],l=n.base?a[0]+n.base:a[0],c=o[l]||0,d="".concat(l," ").concat(c);o[l]=c+1;var h=r(d),u={css:a[1],media:a[2],sourceMap:a[3],supports:a[4],layer:a[5]};if(-1!==h)t[h].references++,t[h].updater(u);else{var p=function(e,t){var r=t.domAPI(t);return r.update(e),function(t){t?(t.css!==e.css||t.media!==e.media||t.sourceMap!==e.sourceMap||t.supports!==e.supports||t.layer!==e.layer)&&r.update(e=t):r.remove()}}(u,n);n.byIndex=i,t.splice(i,0,{identifier:d,updater:p,references:1})}s.push(d)}return s}e.exports=function(e,o){var s=n(e=e||[],o=o||{});return function(e){e=e||[];for(var i=0;i<s.length;i++){var a=r(s[i]);t[a].references--}for(var l=n(e,o),c=0;c<s.length;c++){var d=r(s[c]);0===t[d].references&&(t[d].updater(),t.splice(d,1))}s=l}}},8128(e){var t={};e.exports=function(e,r){var n=function(e){if(void 0===t[e]){var r=document.querySelector(e);if(window.HTMLIFrameElement&&r instanceof window.HTMLIFrameElement)try{r=r.contentDocument.head}catch(e){r=null}t[e]=r}return t[e]}(e);if(!n)throw Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");n.appendChild(r)}},3051(e){e.exports=function(e){var t=document.createElement("style");return e.setAttributes(t,e.attributes),e.insert(t,e.options),t}},855(e,t,r){e.exports=function(e){var t=r.nc;t&&e.setAttribute("nonce",t)}},1740(e){e.exports=function(e){if("u"<typeof document)return{update:function(){},remove:function(){}};var t=e.insertStyleElement(e);return{update:function(r){var n,o,s;n="",r.supports&&(n+="@supports (".concat(r.supports,") {")),r.media&&(n+="@media ".concat(r.media," {")),(o=void 0!==r.layer)&&(n+="@layer".concat(r.layer.length>0?" ".concat(r.layer):""," {")),n+=r.css,o&&(n+="}"),r.media&&(n+="}"),r.supports&&(n+="}"),(s=r.sourceMap)&&"u">typeof btoa&&(n+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(s))))," */")),e.styleTagTransform(n,t,e.options)},remove:function(){var e;null===(e=t).parentNode||e.parentNode.removeChild(e)}}}},3656(e){e.exports=function(e,t){if(t.styleSheet)t.styleSheet.cssText=e;else{for(;t.firstChild;)t.removeChild(t.firstChild);t.appendChild(document.createTextNode(e))}}},4735(e,t,r){r.r(t),r.d(t,{ForkManager:()=>K,IAwarenessProviderFactory:()=>V,IDocumentProviderFactory:()=>J,IForkManagerToken:()=>B,JUPYTER_COLLABORATION_FORK_EVENTS_URI:()=>q,NotebookCellServerExecutor:()=>c,ROOM_FORK_URL:()=>d,RtcContentProvider:()=>m,TimelineWidget:()=>O,WebSocketAwarenessProvider:()=>o,WebSocketProvider:()=>b,requestAPI:()=>h,requestDocSession:()=>u,requestDocumentTimeline:()=>p,requestUndoRedo:()=>_});var n=r(6459);class o extends n.WebsocketProvider{constructor(e){super(e.url,e.roomID,e.awareness.doc,{awareness:e.awareness}),this._isDisposed=!1,this.awareness=e.awareness,this._user=e.user,this._user.ready.then(()=>this._onUserChanged(this._user)).catch(e=>console.error(e)),this._user.userChanged.connect(this._onUserChanged,this)}get isDisposed(){return this._isDisposed}dispose(){this._isDisposed||(this._user.userChanged.disconnect(this._onUserChanged,this),this._isDisposed=!0,this.destroy())}_onUserChanged(e){this.awareness.setLocalStateField("user",e.identity)}}var s=r(5748),i=r(9687),a=r(5374),l=r(9180);class c{constructor(e){var t;this._serverSettings=null!=(t=e.serverSettings)?t:a.ServerConnection.makeSettings()}async runCell({cell:e,notebook:t,notebookConfig:r,onCellExecuted:n,onCellExecutionScheduled:o,sessionContext:c,sessionDialogs:d,translator:h}){var u,p,_;let v=(h=null!=h?h:l.nullTranslator).load("jupyterlab");switch(e.model.type){case"markdown":e.rendered=!0,e.inputHidden=!1,n({cell:e,success:!0});break;case"code":if(c){if(c.isTerminating){await (0,s.showDialog)({title:v.__("Kernel Terminating"),body:v.__("The kernel for %1 appears to be terminating. You can not run any cell for now.",null==(u=c.session)?void 0:u.path),buttons:[s.Dialog.okButton()]});break}if(c.pendingInput)return await (0,s.showDialog)({title:v.__("Cell not executed due to pending input"),body:v.__("The cell has not been executed to avoid kernel deadlock as there is another pending input! Submit your pending input and try again."),buttons:[s.Dialog.okButton()]}),!1;if(c.hasNoKernel&&await c.startKernel()&&d&&await d.selectKernel(c),c.hasNoKernel)return e.model.sharedModel.transact(()=>{e.model.clearExecution()}),!0;let r=null==(_=null==(p=null==c?void 0:c.session)?void 0:p.kernel)?void 0:_.id,l=i.URLExt.join(this._serverSettings.baseUrl,`api/kernels/${r}/execute`),h={method:"POST",body:JSON.stringify({cell_id:e.model.sharedModel.getId(),document_id:t.sharedModel.getState("document_id")})};o({cell:e});let g=!1;try{g=(await a.ServerConnection.makeRequest(l,h,this._serverSettings)).ok}catch(t){if(n({cell:e,success:!1}),e.isDisposed)return!1;throw t}return n({cell:e,success:g}),!0}e.model.sharedModel.transact(()=>{e.model.clearExecution()},!1)}return Promise.resolve(!0)}}let d="api/collaboration/fork";async function h(e="",t={},r){let n,o=null!=r?r:a.ServerConnection.makeSettings(),s=i.URLExt.join(o.baseUrl,e);try{n=await a.ServerConnection.makeRequest(s,t,o)}catch(e){throw new a.ServerConnection.NetworkError(e)}let l=await n.text();if(l.length>0)try{l=JSON.parse(l)}catch(e){console.error("Not a JSON response body.",n)}if(!n.ok)throw new a.ServerConnection.ResponseError(n,l.message||l);return l}async function u(e,t,r,n){let o,s=null!=n?n:a.ServerConnection.makeSettings(),l=i.URLExt.join(s.baseUrl,"api/collaboration/session",encodeURIComponent(r)),c={method:"PUT",body:JSON.stringify({format:e,type:t})};try{o=await a.ServerConnection.makeRequest(l,c,s)}catch(e){throw new a.ServerConnection.NetworkError(e)}let d=await o.text();if(d.length>0)try{d=JSON.parse(d)}catch(e){console.log("Not a JSON response body.",o)}if(!o.ok)throw new a.ServerConnection.ResponseError(o,d.message||d);return d}async function p(e,t,r,n){let o,s=null!=n?n:a.ServerConnection.makeSettings(),l=i.URLExt.join(s.baseUrl,"api/collaboration/timeline",r);l=l.concat(`?format=${e}&&type=${t}`);try{o=await a.ServerConnection.makeRequest(l,{method:"GET"},s)}catch(e){throw new a.ServerConnection.NetworkError(e)}return o}async function _(e,t,r,n,o){let s,l=null!=o?o:a.ServerConnection.makeSettings(),c=i.URLExt.join(l.baseUrl,"api/collaboration/undo_redo",encodeURIComponent(e));c=c.concat(`?action=${t}&&steps=${r}&&forkRoom=${n}`);try{s=await a.ServerConnection.makeRequest(c,{method:"PUT"},l)}catch(e){throw new a.ServerConnection.NetworkError(e)}let d=await s.text();if(d.length>0)try{d=JSON.parse(d)}catch(e){console.log("Not a JSON response body.",s)}if(!s.ok)throw new a.ServerConnection.ResponseError(s,d.message||d);return d}var v=r(6401);let g="true"===i.PageConfig.getOption("disableRTC");class m{constructor(e){var t,r;this._onCreate=(e,t)=>{var r,n,o;if("string"!=typeof e.format)return;let s=()=>{var e,t,r,n;return this._documentManager?null==(e=this._documentManager.autosave)||e:null==(n=null==(r=null==(t=this._docmanagerSettings)?void 0:t.composite)?void 0:r.autosave)||n};if(t.awareness.setLocalStateField("autosave",s()),this._documentManager){let e=(e,r)=>{"autosave"===r.name&&t.awareness.setLocalStateField("autosave",s())};this._documentManager.stateChanged.connect(e),t.disposed.connect(()=>{var t;null==(t=this._documentManager)||t.stateChanged.disconnect(e)})}else if(this._docmanagerSettings){let e=()=>{t.awareness.setLocalStateField("autosave",s())};this._docmanagerSettings.changed.connect(e),t.disposed.connect(()=>{var t;null==(t=this._docmanagerSettings)||t.changed.disconnect(e)})}try{let s={path:e.path,format:e.format,contentType:e.contentType,model:t,user:this._user,translator:this._trans,serverSettings:this._serverSettings,drive:this._currentDrive},i=this._providerFactory.create(s),a=((null==(r=this._globalAwareness)?void 0:r.getLocalState())||{}).documents||[];a.includes(e.path)||(a.push(e.path),null==(n=this._globalAwareness)||n.setLocalStateField("documents",a));let l=e.path,c=`${e.format}:${e.contentType}:${l}`;this._providers.set(c,i);let d=t=>{var r,n;let o=t.oldValue,s=t.newValue;if(!o||!s)return console.debug("New or old path not given",t),!1;if(o!==l&&s===l)return!1;let i=`${e.format}:${e.contentType}:${o}`;if(i!==c)return console.error("The computed old provider key is different from the current key"),!1;let a=`${e.format}:${e.contentType}:${s}`,d=this._providers.get(i);if(!d)return console.warn(`Could not find a provider to update after rename ${i}, ${a}`),!1;this._providers.set(a,d),this._providers.delete(i),c=a,l=s;let h=((null==(r=this._globalAwareness)?void 0:r.getLocalState())||{}).documents||[],u=h.indexOf(o);return h.includes(o)&&!h.includes(s)&&(h.splice(u,1),h.push(s),null==(n=this._globalAwareness)||n.setLocalStateField("documents",h)),this._providerFileChanged.emit({type:"rename",oldValue:{path:o},newValue:{path:s}}),!0},h=(e,t)=>{var r,n;if("rename"!==t.type)return;let o=null==(r=t.oldValue)?void 0:r.path,s=null==(n=t.newValue)?void 0:n.path;o===l&&d({oldValue:o,newValue:s,name:"path"})};null==(o=this._driveFileChanged)||o.connect(h),t.changed.connect(async(e,t)=>{if(!t.stateChange)return;for(let e of t.stateChange.filter(e=>"path"===e.name))d(e);let r=t.stateChange.filter(e=>"hash"===e.name);if(0===r.length)return;r.length>1&&console.error("Unexpected multiple changes to hash value in a single transaction");let n=r[0],o=await this.get(l,{content:!1});this._providerFileChanged.emit({type:"save",newValue:{...o,hash:n.newValue},oldValue:{hash:n.oldValue}})}),t.disposed.connect(()=>{var e,t,r;let n=this._providers.get(c);n&&(n.dispose(),this._providers.delete(c));let o=((null==(e=this._globalAwareness)?void 0:e.getLocalState())||{}).documents||[],s=o.indexOf(l);s>-1&&o.splice(s,1),null==(t=this._globalAwareness)||t.setLocalStateField("documents",o),null==(r=this._driveFileChanged)||r.disconnect(h)})}catch(t){console.error(`Failed to open websocket connection for ${e.path}.
:${t}`)}},this._providerFileChanged=new v.Signal(this),this._user=e.user,this._trans=e.trans,this._globalAwareness=e.globalAwareness,this._serverSettings=e.serverSettings,this._currentDrive=e.currentDrive,this.sharedModelFactory=new f(this._onCreate),this._providers=new Map,this._documentManager=null!=(t=e.documentManager)?t:null,this._docmanagerSettings=null!=(r=e.docmanagerSettings)?r:null,this._driveFileChanged=e.fileChanged,this._providerFactory=e.providerFactory}get providers(){return this._providers}async get(e,t){if(t&&t.format&&t.type){let r=`${t.format}:${t.type}:${e}`,n=this._providers.get(r);if(n){let[r]=await Promise.all([this._currentDrive.get(e,{...t,content:!1,contentProviderId:void 0}),n.ready]);return{...r,format:t.format}}}return this._currentDrive.get(e,{...t,contentProviderId:void 0})}async save(e,t={}){if(t.format&&t.type){let r=`${t.format}:${t.type}:${e}`,n=this._providers.get(r);if(n){n.save&&await n.save();let r={type:t.type,format:t.format,content:!1};return this.get(e,r)}console.warn(`Could not find a provider for ${e}, falling back to REST API save`)}return this._currentDrive.save(e,{...t,contentProviderId:void 0})}get fileChanged(){return this._providerFileChanged}}class f{constructor(e){this._onCreate=e,this.collaborative=!g,this.documentFactories=new Map}registerDocumentFactory(e,t){if(this.documentFactories.has(e))throw Error(`The content type ${e} already exists`);this.documentFactories.set(e,t)}createNew(e){if("string"!=typeof e.format)return void console.warn(`Only defined format are supported; got ${e.format}.`);if(this.collaborative&&e.collaborative&&this.documentFactories.has(e.contentType)){let t=this.documentFactories.get(e.contentType);if(!t)return;let r=t(e);return this._onCreate(e,r),r}}}var y=r(1926),w=r(6214),S=r(7989);class b{constructor(e){var t;this._onLoadTimeout=async()=>{if(this._isDisposed||this._hasSynced||this._isShowingDialog)return;this._isShowingDialog=!0;let e=await (0,s.showDialog)({title:this._trans.__("Loading"),body:this._trans.__("The document is taking some time to load. What would you like to do?"),buttons:[s.Dialog.cancelButton({label:this._trans.__("Cancel")}),s.Dialog.okButton({label:this._trans.__("Continue waiting"),actions:["continue"]}),s.Dialog.warnButton({label:this._trans.__("Retry"),actions:["retry"]})]});if(this._isShowingDialog=!1,!this._isDisposed&&!this._hasSynced)if(e.button.actions.includes("continue"))this._startLoadTimeout();else if(e.button.actions.includes("retry"))await this.reconnect();else{this._disconnect();let e=this._trans.__("The document failed to load. Please try opening it again.");this._ready.reject(e),this._ready.promise.catch(()=>void 0),this._sharedModel.dispose()}},this._onConnectionClosed=async e=>{if([4400,4404,4500].includes(e.code)&&!this._hasSynced){let t=this._getCloseReasonMessage(e.code);this._ready.reject(t),this._sharedModel.dispose()}if(1003===e.code){let t;console.error("Document provider closed:",e.reason);try{t=JSON.parse(e.reason)}catch(r){t={reason:"unknown_session",sessionId:"",reloadable:!1,errorReason:e.reason}}let{title:r,body:n}=this._buildSessionExpiredMessage(t,this._trans);(await (0,s.showDialog)({title:r,body:n,buttons:t.reloadable?[s.Dialog.cancelButton({label:this._trans.__("Continue")}),s.Dialog.okButton({label:this._trans.__("Reload")})]:[s.Dialog.okButton({label:this._trans.__("Ok")})]})).button.accept&&t.reloadable&&window.location.reload(),this._sharedModel.dispose()}},this._handleConflictMessage=async e=>{var t,r,n;if(!(e.data instanceof ArrayBuffer))return;let o=new Uint8Array(e.data);if(0===o.length)return;let i=y.$C(o);try{if(2!==y.cw(i))return;let e=JSON.parse(y.t3(i));if(!e||"conflict"!==e.type)return}catch(e){return}let a=[s.Dialog.cancelButton({label:this._trans.__("Dismiss")})];this._onConflictRevert&&a.push(s.Dialog.warnButton({label:this._trans.__("Revert"),actions:["revert"]})),this._onConflictShowDiff&&a.push(s.Dialog.okButton({label:this._trans.__("Show Diff"),actions:["show-diff"]})),this._onConflictSaveAs&&a.push(s.Dialog.okButton({label:this._trans.__("Save As"),actions:["save-as"]}));let l=await (0,s.showDialog)({title:this._trans.__("Edit Conflict"),body:this._trans.__("Your recent changes could not be applied because the document structure changed while you were disconnected (for example, another user or external tool modified the file). Your edits were not saved to the shared document."),buttons:a});l.button.actions.includes("revert")?await (null==(t=this._onConflictRevert)?void 0:t.call(this)):l.button.actions.includes("show-diff")?await (null==(r=this._onConflictShowDiff)?void 0:r.call(this,this._sharedModel.getSource())):l.button.actions.includes("save-as")&&await (null==(n=this._onConflictSaveAs)?void 0:n.call(this))},this._onSync=e=>{e&&(this._hasSynced=!0,this._clearLoadTimeout(),this._yWebsocketProvider&&(this._yWebsocketProvider.off("sync",this._onSync),this._sharedModel.ydoc.getMap("state").set("document_id",this._yWebsocketProvider.roomname)),this._ready.resolve())},this._ready=new S.PromiseDelegate,this._hasSynced=!1,this._saveCounter=0,this._conflictWs=null,this._loadTimeoutId=null,this._isShowingDialog=!1,this._isDisposed=!1,this._path=e.path,this._contentType=e.contentType,this._format=e.format,this._customServerUrl=e.url,this._sharedModel=e.model,this._awareness=e.model.awareness,this._yWebsocketProvider=null,this._serverSettings=null!=(t=e.serverSettings)?t:a.ServerConnection.makeSettings(),this._trans=e.translator,this._onConflictSaveAs=e.onConflictSaveAs,this._onConflictRevert=e.onConflictRevert,this._onConflictShowDiff=e.onConflictShowDiff;const r=e.user;r.ready.then(()=>{this._onUserChanged(r)}).catch(e=>console.error(e)),r.userChanged.connect(this._onUserChanged,this),this._connect().catch(e=>console.warn(e)),this._startLoadTimeout()}get isDisposed(){return this._isDisposed}get ready(){return this._ready.promise}get contentType(){return this._contentType}get format(){return this._format}dispose(){var e,t,r;this.isDisposed||(this._isDisposed=!0,this._clearLoadTimeout(),this._conflictWs&&(this._conflictWs.removeEventListener("message",this._handleConflictMessage),this._conflictWs=null),null==(e=this._yWebsocketProvider)||e.off("connection-close",this._onConnectionClosed),null==(t=this._yWebsocketProvider)||t.off("sync",this._onSync),null==(r=this._yWebsocketProvider)||r.destroy(),this._disconnect(),v.Signal.clearData(this))}async reconnect(){this._clearLoadTimeout(),this._disconnect(),this._connect().catch(e=>console.warn(e))}async save(){var e;let t=null==(e=this._yWebsocketProvider)?void 0:e.ws;if(t){let e=++this._saveCounter,r=new S.PromiseDelegate,n=t=>{let n=new Uint8Array(t.data),o=y.$C(n);try{if(2!==y.cw(o))return}catch(e){return}let s=y.t3(o),i=null;try{i=JSON.parse(s)}catch(e){console.debug("The raw reply received was not a JSON reply")}i&&"save"===i.type&&i.responseTo===e&&("success"===i.status?r.resolve():"failed"===i.status?r.reject("Saving failed"):"skipped"===i.status?r.reject("Saving already in progress"):r.reject("Unrecognised save reply status"))};t.addEventListener("message",n);let o=w.xv();w.zd(o,2),w.Qj(o,"save"),w.zd(o,e);let s=w.Fo(o);t.send(s);try{await r.promise}finally{t.removeEventListener("message",n)}}}get _serverUrl(){var e;return null!=(e=this._customServerUrl)?e:i.URLExt.join(this._serverSettings.wsUrl,"api/collaboration/room")}async _connect(){let e=await u(this._format,this._contentType,this._path,this._serverSettings),t=this._serverSettings.token,r={sessionId:e.sessionId};this._serverSettings.appendToken&&""!==t&&(r.token=t),this._yWebsocketProvider=new n.WebsocketProvider(this._serverUrl,`${e.format}:${e.type}:${e.fileId}`,this._sharedModel.ydoc,{disableBc:!0,params:r,awareness:this._awareness,WebSocketPolyfill:this._serverSettings.WebSocket}),this._yWebsocketProvider.on("sync",this._onSync),this._yWebsocketProvider.on("connection-close",this._onConnectionClosed),this._yWebsocketProvider.on("status",({status:e})=>{"connected"===e&&this._attachConflictListener()}),this._startLoadTimeout()}_startLoadTimeout(){this._clearLoadTimeout(),this._isDisposed||(this._loadTimeoutId=window.setTimeout(()=>{this._onLoadTimeout()},5e3))}_clearLoadTimeout(){null!==this._loadTimeoutId&&(clearTimeout(this._loadTimeoutId),this._loadTimeoutId=null)}async connectToForkDoc(e,t){let r=this._serverSettings.token,o={sessionId:t};this._serverSettings.appendToken&&""!==r&&(o.token=r),this._disconnect(),this._yWebsocketProvider=new n.WebsocketProvider(this._serverUrl,e,this._sharedModel.ydoc,{disableBc:!0,params:o,awareness:this._awareness,WebSocketPolyfill:this._serverSettings.WebSocket})}get wsProvider(){return this._yWebsocketProvider}_disconnect(){var e,t,r;null==(e=this._yWebsocketProvider)||e.off("connection-close",this._onConnectionClosed),null==(t=this._yWebsocketProvider)||t.off("sync",this._onSync),null==(r=this._yWebsocketProvider)||r.destroy(),this._yWebsocketProvider=null}_onUserChanged(e){this._awareness.setLocalStateField("user",e.identity)}_buildSessionExpiredMessage(e,t){switch(e.reason){case"version_mismatch":return{title:t.__("Collaboration extension updated"),body:t.__("Reload the browser tab to load the new version.")};case"initialization_error":return{title:t.__("Document error"),body:t.__("Failed to initialize the document. Close this tab and reopen the file.")};default:return{title:t.__("Session expired"),body:e.errorReason?t.__(e.errorReason):t.__("Reload the browser tab to continue.")}}}_attachConflictListener(){var e;this._conflictWs&&this._conflictWs.removeEventListener("message",this._handleConflictMessage);let t=null==(e=this._yWebsocketProvider)?void 0:e.ws;t&&(t.addEventListener("message",this._handleConflictMessage),this._conflictWs=t)}_getCloseReasonMessage(e){switch(e){case 4400:return this._trans.__("Bad request for %1",this._path);case 4404:return this._trans.__("Could not find %1",this._path);case 4500:return this._trans.__("Internal server error when loading %1",this._path)}}}var C=r(5524),k=r.n(C),T=r(2591),D=r.n(T),R=r(1740),E=r.n(R),x=r(8128),L=r.n(x),P=r(855),U=r.n(P),$=r(3051),M=r.n($),F=r(3656),I=r.n(F),j=r(5068),N={};N.styleTagTransform=I(),N.setAttributes=U(),N.insert=L().bind(null,"head"),N.domAPI=E(),N.insertStyleElement=M(),D()(j.A,N),j.A&&j.A.locals&&j.A.locals;var W=r(5518);let A=({apiURL:e,provider:t,contentType:r,format:n,documentTimelineUrl:o,serverSettings:i})=>{let a,l,c,d,h,v,g,[m,f]=(0,C.useState)({roomId:"",timestamps:[],forkRoom:"",sessionId:""}),[y,w]=(0,C.useState)(m.timestamps.length-1),[S,b]=(0,C.useState)(!1),[T,D]=(0,C.useState)(!1),R=(0,C.useRef)(!0),E=(0,C.useRef)(!0),x=(0,C.useRef)(null);async function L(o){try{if(R.current){let a=await p(n,r,o,i);if(!a.ok)if(404===a.status)throw Error("Not found");else if(503===a.status)throw Error("WebSocket closed");else throw Error(`Failed to fetch data: ${a.statusText}`);let l=await a.text(),c={roomId:"",timestamps:[],forkRoom:"",sessionId:""};return l&&(s.Notification.warning("Document is now in read-only mode. Changes will not be saved.",{autoClose:2500}),c=JSON.parse(l),f(c),w(c.timestamps.length-1),t.connectToForkDoc(c.forkRoom,c.sessionId),x.current=await u(n,r,$(e),i)),b(!0),R.current=!1,c}}catch(e){console.error("Error fetching data:",e)}}let P=async()=>{if(!x.current)return void console.error("Session is not initialized");let e=await _(`${x.current.format}:${x.current.type}:${x.current.fileId}`,"restore",0,m.forkRoom,i);200===e.code?(s.Notification.success(e.status,{autoClose:4e3}),t.reconnect(),b(!1),R.current=!0):s.Notification.error(e.status,{autoClose:4e3})},U=async e=>{let t=parseInt(e.target.value),r=Math.abs(t-y);try{let e=t<y?"undo":"redo";if(w(t),E.current&&(D(!0),E.current=!1),!x.current)return void console.error("Session is not initialized");await _(`${x.current.format}:${x.current.type}:${x.current.fileId}`,e,r,m.forkRoom,i)}catch(e){console.error("Error fetching or applying updates:",e)}};function $(e){try{let t=new URL(e).pathname,r=t.lastIndexOf(o);if(-1===r)throw Error(`API segment "${o}" not found in URL.`);return t.slice(r+o.length)}catch(e){return console.error("Invalid URL or unable to extract filename:",e),""}}return k().createElement("div",{className:"jp-sliderContainer"},k().createElement("div",{onClick:()=>{L($(e))},className:"jp-mod-highlighted",title:"Document Timeline"},k().createElement(W.historyIcon.react,{marginRight:"4px"})),S&&k().createElement("div",{className:"jp-timestampDisplay"},k().createElement("input",{type:"range",min:0,max:m.timestamps.length-1,value:y,onChange:U,className:"jp-Slider"}),k().createElement("div",null,k().createElement("strong",null,$(e).split("/").pop()," ")," "),T&&k().createElement("div",{className:"jp-restoreBtnContainer"},k().createElement("button",{onClick:P,className:"jp-ToolbarButtonComponent jp-restoreBtn"},"Restore version"," ",(l=(a=new Date(1e3*m.timestamps[y])).getFullYear(),c=String(a.getMonth()+1).padStart(2,"0"),d=String(a.getDate()).padStart(2,"0"),h=String(a.getHours()).padStart(2,"0"),v=String(a.getMinutes()).padStart(2,"0"),g=String(a.getSeconds()).padStart(2,"0"),`${l}-${c}-${d} ${h}:${v}:${g}`)))))};class O extends s.ReactWidget{constructor(e,t,r,n,o,s){super(),this.apiURL=e,this.provider=t,this.contentType=r,this.format=n,this.documentTimelineUrl=o,this._serverSettings=s,this.addClass("jp-timelineSliderWrapper")}render(){return C.createElement(A,{key:this.apiURL,apiURL:this.apiURL,provider:this.provider,contentType:this.contentType,format:this.format,documentTimelineUrl:this.documentTimelineUrl,serverSettings:this._serverSettings})}updateContent(e,t){this.apiURL=e,this.provider=t,this.contentType=this.provider.contentType,this.format=this.provider.format,this.update()}}let B=new S.Token("@jupyter/docprovider:IForkManagerToken"),J=new S.Token("@jupyter/docprovider:IDocumentProviderFactory"),V=new S.Token("@jupyter/docprovider:IAwarenessProviderFactory"),q="https://schema.jupyter.org/jupyter_collaboration/fork/v1";class K{constructor(e){this._disposed=!1,this._forkAddedSignal=new v.Signal(this),this._forkDeletedSignal=new v.Signal(this);const{contentProvider:t,eventManager:r}=e;this._contentProvider=t,this._eventManager=r,this._eventManager.stream.connect(this._handleEvent,this),this._serverSettings=e.serverSettings}get isDisposed(){return this._disposed}get forkAdded(){return this._forkAddedSignal}get forkDeleted(){return this._forkDeletedSignal}dispose(){var e;this._disposed||(null==(e=this._eventManager)||e.stream.disconnect(this._handleEvent),this._disposed=!0)}async createFork(e){let{rootId:t,title:r,description:n,synchronize:o}=e,s={method:"PUT",body:JSON.stringify({title:r,description:n,synchronize:o})},a=i.URLExt.join(d,t);return await h(a,s,this._serverSettings)}async getAllForks(e){let t=i.URLExt.join(d,e);return await h(t,{method:"GET"},this._serverSettings)}async deleteFork(e){let{forkId:t,merge:r}=e,n=i.URLExt.join(d,t),o=i.URLExt.objectToQueryString({merge:r});await h(`${n}${o}`,{method:"DELETE"},this._serverSettings)}getProvider(e){let{documentPath:t,format:r,type:n}=e,o=this._contentProvider;if(o)return o.providers.get(`${r}:${n}:${t}`)}_handleEvent(e,t){if(t.schema_id===q)switch(t.action){case"create":this._forkAddedSignal.emit(t);break;case"delete":this._forkDeletedSignal.emit(t)}}}}}]);