Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/collaboration-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@
"@jupyterlab/apputils": "^4.7.0-beta.1",
"@jupyterlab/codemirror": "^4.6.0-beta.1",
"@jupyterlab/coreutils": "^6.6.0-beta.1",
"@jupyterlab/docregistry": "^4.6.0-beta.1",
"@jupyterlab/services": "^7.6.0-beta.1",
"@jupyterlab/statedb": "^4.6.0-beta.1",
"@jupyterlab/statusbar": "^4.6.0-beta.1",
"@jupyterlab/translation": "^4.6.0-beta.1",
"@jupyterlab/ui-components": "^4.6.0-beta.1",
"@lumino/widgets": "^2.8.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/collaboration-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
userEditorCursors
} from './collaboration';
import { sharedLink } from './sharedlink';
import { statusBarTimeline } from './timeline';

/**
* Export the plugins as default.
Expand All @@ -25,6 +26,7 @@ const plugins: JupyterFrontEndPlugin<any>[] = [
rtcGlobalAwarenessPlugin,
rtcPanelPlugin,
sharedLink,
statusBarTimeline,
userEditorCursors
];

Expand Down
124 changes: 124 additions & 0 deletions packages/collaboration-extension/src/timeline.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import {
JupyterFrontEnd,
JupyterFrontEndPlugin
} from '@jupyterlab/application';
import { URLExt } from '@jupyterlab/coreutils';
import { DocumentWidget } from '@jupyterlab/docregistry';
import { IStatusBar } from '@jupyterlab/statusbar';
import { Widget } from '@lumino/widgets';

import { TimelineWidget } from '@jupyter/collaboration';
import { ICollaborativeContentProvider } from '@jupyter/collaborative-drive';
import { IForkProvider } from '@jupyter/docprovider';

const DOCUMENT_TIMELINE_URL = 'api/collaboration/timeline';

/**
* A plugin to add a timeline slider status item to the status bar.
*/
export const statusBarTimeline: JupyterFrontEndPlugin<void> = {
id: '@jupyter/collaboration-extension:statusBarTimeline',
description: 'Plugin to add a timeline slider to the status bar',
autoStart: true,
requires: [IStatusBar, ICollaborativeContentProvider],
activate: async (
app: JupyterFrontEnd,
statusBar: IStatusBar,
contentProvider: ICollaborativeContentProvider
): Promise<void> => {
try {
let sliderItem: Widget | null = null;
let timelineWidget: TimelineWidget | null = null;

const updateTimelineForDocument = async (
documentPath: string,
documentId: string
) => {
if (!documentId) {
return;
}
// Dispose of the previous timelineWidget if it exists
if (timelineWidget) {
timelineWidget.dispose();
timelineWidget = null;
}

const [format, type] = documentId.split(':');
const provider = contentProvider.providers.get(
`${format}:${type}:${documentPath}`
);
if (!provider) {
// this can happen for documents which are not provisioned with RTC
return;
}

const forkProvider = provider as unknown as IForkProvider;

const fullPath = URLExt.join(
app.serviceManager.serverSettings.baseUrl,
DOCUMENT_TIMELINE_URL,
documentPath
);

timelineWidget = new TimelineWidget(
fullPath,
forkProvider,
forkProvider.contentType,
forkProvider.format,
DOCUMENT_TIMELINE_URL,
app.serviceManager.serverSettings
);

const elt = document.getElementById('jp-slider-status-bar');
if (elt && !timelineWidget.isAttached) {
Widget.attach(timelineWidget, elt);
}
};

if (app.shell.currentChanged) {
app.shell.currentChanged.connect(async (_, args) => {
const currentWidget = args.newValue as DocumentWidget;
if (timelineWidget) {
// Dispose of the timelineWidget when the document is closed
timelineWidget.dispose();
timelineWidget = null;
}
if (currentWidget && 'context' in currentWidget) {
await currentWidget.context.ready;
await updateTimelineForDocument(
currentWidget.context.path,
currentWidget.context.model.sharedModel.getState(
'document_id'
) as string
);
}
});
}

if (statusBar) {
if (!sliderItem) {
sliderItem = new Widget();
sliderItem.addClass('jp-StatusBar-GroupItem');
sliderItem.addClass('jp-mod-highlighted');
sliderItem.id = 'jp-slider-status-bar';
statusBar.registerStatusItem('jp-slider-status-bar', {
item: sliderItem,
align: 'left',
rank: 4,
isActive: () => {
const currentWidget = app.shell
.currentWidget as DocumentWidget | null;

return currentWidget?.context?.model?.collaborative || false;
}
});
}
}
} catch (error) {
console.error('Failed to activate statusBarTimeline plugin:', error);
}
}
};
1 change: 1 addition & 0 deletions packages/collaboration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"dependencies": {
"@codemirror/state": "^6.2.0",
"@codemirror/view": "^6.7.0",
"@jupyter/docprovider": "^5.0.0-alpha.0",
"@jupyterlab/apputils": "^4.7.0-beta.1",
"@jupyterlab/coreutils": "^6.6.0-beta.1",
"@jupyterlab/docregistry": "^4.6.0-beta.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { ReactWidget } from '@jupyterlab/apputils';
import { TimelineSliderComponent } from './component';
import * as React from 'react';
import { IForkProvider } from './ydrive';
import { IForkProvider } from '@jupyter/docprovider';
import { ServerConnection } from '@jupyterlab/services';

export class TimelineWidget extends ReactWidget {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
|----------------------------------------------------------------------------*/

import React, { useState, useRef } from 'react';
import '../style/slider.css';
import {
IForkProvider,
requestUndoRedo,
requestDocSession,
requestDocumentTimeline
} from './requests';
} from '@jupyter/docprovider';
import { historyIcon } from '@jupyterlab/ui-components';
import { Notification } from '@jupyterlab/apputils';
import { IForkProvider } from './ydrive';
import { ServerConnection } from '@jupyterlab/services';

type Props = {
Expand Down
1 change: 1 addition & 0 deletions packages/collaboration/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ export * from './collaboratorspanel';
export * from './cursors';
export * from './menu';
export * from './sharedlink';
export * from './TimelineSlider';
export * from './userinfopanel';
export * from './users-item';
1 change: 1 addition & 0 deletions packages/collaboration/style/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@import url('./sidepanel.css');
@import url('./users-item.css');
@import url('./sharedlink.css');
@import url('./slider.css');

.jp-shared-link-body {
user-select: none;
Expand Down
115 changes: 1 addition & 114 deletions packages/docprovider-extension/src/filebrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import {
JupyterFrontEndPlugin
} from '@jupyterlab/application';
import { Dialog, showDialog } from '@jupyterlab/apputils';
import { DocumentWidget, IDocumentWidget } from '@jupyterlab/docregistry';
import { Widget } from '@lumino/widgets';
import { IDocumentWidget } from '@jupyterlab/docregistry';

import { IStatusBar } from '@jupyterlab/statusbar';
import { ContentsManager } from '@jupyterlab/services';

import { IDocumentManager } from '@jupyterlab/docmanager';
Expand All @@ -36,15 +34,10 @@ import {
IGlobalAwareness
} from '@jupyter/collaborative-drive';
import {
IForkProvider,
TimelineWidget,
RtcContentProvider,
IDocumentProviderFactory
} from '@jupyter/docprovider';
import { Awareness } from 'y-protocols/awareness';
import { URLExt } from '@jupyterlab/coreutils';

const DOCUMENT_TIMELINE_URL = 'api/collaboration/timeline';

const TWO_SESSIONS_WARNING =
'The file %1 has been opened with two different views. ' +
Expand Down Expand Up @@ -169,112 +162,6 @@ export const ynotebook: JupyterFrontEndPlugin<void> = {
notebookFactory.contentProviderId = 'rtc';
}
};
/**
* A plugin to add a timeline slider status item to the status bar.
*/
export const statusBarTimeline: JupyterFrontEndPlugin<void> = {
id: '@jupyter/docprovider-extension:statusBarTimeline',
description: 'Plugin to add a timeline slider to the status bar',
autoStart: true,
requires: [IStatusBar, ICollaborativeContentProvider],
activate: async (
app: JupyterFrontEnd,
statusBar: IStatusBar,
contentProvider: ICollaborativeContentProvider
): Promise<void> => {
try {
let sliderItem: Widget | null = null;
let timelineWidget: TimelineWidget | null = null;

const updateTimelineForDocument = async (
documentPath: string,
documentId: string
) => {
if (!documentId) {
return;
}
// Dispose of the previous timelineWidget if it exists
if (timelineWidget) {
timelineWidget.dispose();
timelineWidget = null;
}

const [format, type] = documentId.split(':');
const provider = contentProvider.providers.get(
`${format}:${type}:${documentPath}`
);
if (!provider) {
// this can happen for documents which are not provisioned with RTC
return;
}

const forkProvider = provider as unknown as IForkProvider;

const fullPath = URLExt.join(
app.serviceManager.serverSettings.baseUrl,
DOCUMENT_TIMELINE_URL,
documentPath
);

timelineWidget = new TimelineWidget(
fullPath,
forkProvider,
forkProvider.contentType,
forkProvider.format,
DOCUMENT_TIMELINE_URL,
app.serviceManager.serverSettings
);

const elt = document.getElementById('jp-slider-status-bar');
if (elt && !timelineWidget.isAttached) {
Widget.attach(timelineWidget, elt);
}
};

if (app.shell.currentChanged) {
app.shell.currentChanged.connect(async (_, args) => {
const currentWidget = args.newValue as DocumentWidget;
if (timelineWidget) {
// Dispose of the timelineWidget when the document is closed
timelineWidget.dispose();
timelineWidget = null;
}
if (currentWidget && 'context' in currentWidget) {
await currentWidget.context.ready;
await updateTimelineForDocument(
currentWidget.context.path,
currentWidget.context.model.sharedModel.getState(
'document_id'
) as string
);
}
});
}

if (statusBar) {
if (!sliderItem) {
sliderItem = new Widget();
sliderItem.addClass('jp-StatusBar-GroupItem');
sliderItem.addClass('jp-mod-highlighted');
sliderItem.id = 'jp-slider-status-bar';
statusBar.registerStatusItem('jp-slider-status-bar', {
item: sliderItem,
align: 'left',
rank: 4,
isActive: () => {
const currentWidget = app.shell
.currentWidget as DocumentWidget | null;

return currentWidget?.context?.model?.collaborative || false;
}
});
}
}
} catch (error) {
console.error('Failed to activate statusBarTimeline plugin:', error);
}
}
};

/**
* The default collaborative drive provider.
Expand Down
9 changes: 1 addition & 8 deletions packages/docprovider-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@

import { JupyterFrontEndPlugin } from '@jupyterlab/application';

import {
rtcContentProvider,
yfile,
ynotebook,
logger,
statusBarTimeline
} from './filebrowser';
import { rtcContentProvider, yfile, ynotebook, logger } from './filebrowser';
import { notebookCellExecutor } from './executor';
import { forkManagerPlugin } from './forkManager';
import {
Expand All @@ -30,7 +24,6 @@ const plugins: JupyterFrontEndPlugin<unknown>[] = [
ynotebook,
logger,
notebookCellExecutor,
statusBarTimeline,
forkManagerPlugin,
documentProviderFactoryPlugin,
awarenessProviderFactoryPlugin
Expand Down
1 change: 0 additions & 1 deletion packages/docprovider/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ export * from './notebookCellExecutor';
export * from './requests';
export * from './ydrive';
export * from './yprovider';
export * from './TimelineSlider';
export * from './tokens';
export * from './forkManager';
2 changes: 0 additions & 2 deletions packages/docprovider/style/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|---------------------------------------------------------------------------- */

@import url('./slider.css');
3 changes: 3 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2072,8 +2072,10 @@ __metadata:
"@jupyterlab/builder": ^4.6.0-alpha.5
"@jupyterlab/codemirror": ^4.6.0-beta.1
"@jupyterlab/coreutils": ^6.6.0-beta.1
"@jupyterlab/docregistry": ^4.6.0-beta.1
"@jupyterlab/services": ^7.6.0-beta.1
"@jupyterlab/statedb": ^4.6.0-beta.1
"@jupyterlab/statusbar": ^4.6.0-beta.1
"@jupyterlab/translation": ^4.6.0-beta.1
"@jupyterlab/ui-components": ^4.6.0-beta.1
"@lumino/widgets": ^2.8.0
Expand All @@ -2093,6 +2095,7 @@ __metadata:
dependencies:
"@codemirror/state": ^6.2.0
"@codemirror/view": ^6.7.0
"@jupyter/docprovider": ^5.0.0-alpha.0
"@jupyterlab/apputils": ^4.7.0-beta.1
"@jupyterlab/coreutils": ^6.6.0-beta.1
"@jupyterlab/docregistry": ^4.6.0-beta.1
Expand Down
Loading