"use strict";(self.rspackChunk_jupyter_collaboration_extension=self.rspackChunk_jupyter_collaboration_extension||[]).push([[44],{5068(e,t,r){var o=r(6758),n=r.n(o),s=r(935),i=r.n(s)()(n());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="",o=void 0!==t[5];return t[4]&&(r+="@supports (".concat(t[4],") {")),t[2]&&(r+="@media ".concat(t[2]," {")),o&&(r+="@layer".concat(t[5].length>0?" ".concat(t[5]):""," {")),r+=e(t),o&&(r+="}"),t[2]&&(r+="}"),t[4]&&(r+="}"),r}).join("")},t.i=function(e,r,o,n,s){"string"==typeof e&&(e=[[null,e,void 0]]);var i={};if(o)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]);o&&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),n&&(d[4]?(d[1]="@supports (".concat(d[4],") {").concat(d[1],"}"),d[4]=n):d[4]="".concat(n)),t.push(d))}},t}},6758(e){e.exports=function(e){return e[1]}},2591(e){var t=[];function r(e){for(var r=-1,o=0;o<t.length;o++)if(t[o].identifier===e){r=o;break}return r}function o(e,o){for(var n={},s=[],i=0;i<e.length;i++){var a=e[i],l=o.base?a[0]+o.base:a[0],c=n[l]||0,d="".concat(l," ").concat(c);n[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,o);o.byIndex=i,t.splice(i,0,{identifier:d,updater:p,references:1})}s.push(d)}return s}e.exports=function(e,n){var s=o(e=e||[],n=n||{});return function(e){e=e||[];for(var i=0;i<s.length;i++){var a=r(s[i]);t[a].references--}for(var l=o(e,n),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 o=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(!o)throw Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");o.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 o,n,s;o="",r.supports&&(o+="@supports (".concat(r.supports,") {")),r.media&&(o+="@media ".concat(r.media," {")),(n=void 0!==r.layer)&&(o+="@layer".concat(r.layer.length>0?" ".concat(r.layer):""," {")),o+=r.css,n&&(o+="}"),r.media&&(o+="}"),r.supports&&(o+="}"),(s=r.sourceMap)&&"u">typeof btoa&&(o+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(s))))," */")),e.styleTagTransform(o,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:()=>q,IDocumentProviderFactory:()=>J,IForkManagerToken:()=>B,JUPYTER_COLLABORATION_FORK_EVENTS_URI:()=>V,NotebookCellServerExecutor:()=>c,ROOM_FORK_URL:()=>d,RtcContentProvider:()=>m,TimelineWidget:()=>O,WebSocketAwarenessProvider:()=>n,WebSocketProvider:()=>b,requestAPI:()=>h,requestDocSession:()=>u,requestDocumentTimeline:()=>p,requestUndoRedo:()=>_});var o=r(6459);class n extends o.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:o,onCellExecutionScheduled:n,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,o({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")})};n({cell:e});let g=!1;try{g=(await a.ServerConnection.makeRequest(l,h,this._serverSettings)).ok}catch(t){if(o({cell:e,success:!1}),e.isDisposed)return!1;throw t}return o({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 o,n=null!=r?r:a.ServerConnection.makeSettings(),s=i.URLExt.join(n.baseUrl,e);try{o=await a.ServerConnection.makeRequest(s,t,n)}catch(e){throw new a.ServerConnection.NetworkError(e)}let l=await o.text();if(l.length>0)try{l=JSON.parse(l)}catch(e){console.error("Not a JSON response body.",o)}if(!o.ok)throw new a.ServerConnection.ResponseError(o,l.message||l);return l}async function u(e,t,r,o){let n,s=null!=o?o: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{n=await a.ServerConnection.makeRequest(l,c,s)}catch(e){throw new a.ServerConnection.NetworkError(e)}let d=await n.text();if(d.length>0)try{d=JSON.parse(d)}catch(e){console.log("Not a JSON response body.",n)}if(!n.ok)throw new a.ServerConnection.ResponseError(n,d.message||d);return d}async function p(e,t,r,o){let n,s=null!=o?o:a.ServerConnection.makeSettings(),l=i.URLExt.join(s.baseUrl,"api/collaboration/timeline",r);l=l.concat(`?format=${e}&&type=${t}`);try{n=await a.ServerConnection.makeRequest(l,{method:"GET"},s)}catch(e){throw new a.ServerConnection.NetworkError(e)}return n}async function _(e,t,r,o,n){let s,l=null!=n?n:a.ServerConnection.makeSettings(),c=i.URLExt.join(l.baseUrl,"api/collaboration/undo_redo",encodeURIComponent(e));c=c.concat(`?action=${t}&&steps=${r}&&forkRoom=${o}`);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,o,n;if("string"!=typeof e.format)return;let s=()=>{var e,t,r,o;return this._documentManager?null==(e=this._documentManager.autosave)||e:null==(o=null==(r=null==(t=this._docmanagerSettings)?void 0:t.composite)?void 0:r.autosave)||o};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==(o=this._globalAwareness)||o.setLocalStateField("documents",a));let l=e.path,c=`${e.format}:${e.contentType}:${l}`;this._providers.set(c,i);let d=t=>{var r,o;let n=t.oldValue,s=t.newValue;if(!n||!s)return void console.debug("New or old path not given",t);let i=`${e.format}:${e.contentType}:${n}`;if(i!==c)return void console.error("The computed old provider key is different from the current key");let a=`${e.format}:${e.contentType}:${s}`,d=this._providers.get(i);if(!d)return void console.warn(`Could not find a provider to update after rename ${i}, ${a}`);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(n);h.includes(n)&&!h.includes(s)&&(h.splice(u,1),h.push(s),null==(o=this._globalAwareness)||o.setLocalStateField("documents",h))},h=(e,t)=>{var r,o;if("rename"!==t.type)return;let n=null==(r=t.oldValue)?void 0:r.path,s=null==(o=t.newValue)?void 0:o.path;n===l&&d({oldValue:n,newValue:s,name:"path"})};null==(n=this._driveFileChanged)||n.connect(h),t.changed.connect(async(r,o)=>{var n;if(!o.stateChange)return;for(let e of o.stateChange.filter(e=>"path"===e.name))d(e);let s=o.stateChange.filter(e=>"hash"===e.name);if(0===s.length)return;s.length>1&&console.error("Unexpected multiple changes to hash value in a single transaction");let i=s[0],a=null!=(n=t.state.path)?n:e.path,l=await this.get(a,{content:!1});this._providerFileChanged.emit({type:"save",newValue:{...l,hash:i.newValue},oldValue:{hash:i.oldValue}})}),t.disposed.connect(()=>{var e,t,r;let o=this._providers.get(c);o&&(o.dispose(),this._providers.delete(c));let n=((null==(e=this._globalAwareness)?void 0:e.getLocalState())||{}).documents||[],s=n.indexOf(l);s>-1&&n.splice(s,1),null==(t=this._globalAwareness)||t.setLocalStateField("documents",n),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}`,o=this._providers.get(r);if(o){let[r]=await Promise.all([this._currentDrive.get(e,{...t,content:!1,contentProviderId:void 0}),o.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}`,o=this._providers.get(r);if(o){o.save&&await o.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:o}=this._buildSessionExpiredMessage(t,this._trans);(await (0,s.showDialog)({title:r,body:o,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,o;if(!(e.data instanceof ArrayBuffer))return;let n=new Uint8Array(e.data);if(0===n.length)return;let i=y.$C(n);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==(o=this._onConflictSaveAs)?void 0:o.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,o=t=>{let o=new Uint8Array(t.data),n=y.$C(o);try{if(2!==y.cw(n))return}catch(e){return}let s=y.t3(n),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",o);let n=w.xv();w.zd(n,2),w.Qj(n,"save"),w.zd(n,e);let s=w.Fo(n);t.send(s);try{await r.promise}finally{t.removeEventListener("message",o)}}}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 o.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,n={sessionId:t};this._serverSettings.appendToken&&""!==r&&(n.token=r),this._disconnect(),this._yWebsocketProvider=new o.WebsocketProvider(this._serverUrl,e,this._sharedModel.ydoc,{disableBc:!0,params:n,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($),I=r(3656),F=r.n(I),j=r(5068),N={};N.styleTagTransform=F(),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:o,documentTimelineUrl:n,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(n){try{if(R.current){let a=await p(o,r,n,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(o,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(n);if(-1===r)throw Error(`API segment "${n}" not found in URL.`);return t.slice(r+n.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,o,n,s){super(),this.apiURL=e,this.provider=t,this.contentType=r,this.format=o,this.documentTimelineUrl=n,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"),q=new S.Token("@jupyter/docprovider:IAwarenessProviderFactory"),V="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:o,synchronize:n}=e,s={method:"PUT",body:JSON.stringify({title:r,description:o,synchronize:n})},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,o=i.URLExt.join(d,t),n=i.URLExt.objectToQueryString({merge:r});await h(`${o}${n}`,{method:"DELETE"},this._serverSettings)}getProvider(e){let{documentPath:t,format:r,type:o}=e,n=this._contentProvider;if(n)return n.providers.get(`${r}:${o}:${t}`)}_handleEvent(e,t){if(t.schema_id===V)switch(t.action){case"create":this._forkAddedSignal.emit(t);break;case"delete":this._forkDeletedSignal.emit(t)}}}}}]);