Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jupyterlab/jupyter-collaboration
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: @jupyter/collaboration-extension@1.0.0-alpha.6
Choose a base ref
...
head repository: jupyterlab/jupyter-collaboration
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 9d8475f5cc333e22b50160ec32e508a4e8c75c06
Choose a head ref
  • 2 commits
  • 9 files changed
  • 1 contributor

Commits on Mar 29, 2023

  1. Allow other extensions to register shared models (#133)

    * Allow registering factories for shared models to other extensions
    
    * Lint
    hbcarlos authored Mar 29, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    26ff6c7 View commit details
  2. Update dependencies (#134)

    hbcarlos authored Mar 29, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    9d8475f View commit details
22 changes: 11 additions & 11 deletions packages/collaboration-extension/package.json
Original file line number Diff line number Diff line change
@@ -55,24 +55,24 @@
"dependencies": {
"@jupyter/collaboration": "^1.0.0-alpha.6",
"@jupyter/docprovider": "^1.0.0-alpha.6",
"@jupyterlab/application": "^4.0.0-alpha.22",
"@jupyterlab/apputils": "^4.0.0-alpha.22",
"@jupyterlab/codemirror": "^4.0.0-alpha.22",
"@jupyterlab/coreutils": "^6.0.0-alpha.22",
"@jupyterlab/filebrowser": "^4.0.0-alpha.22",
"@jupyterlab/services": "^7.0.0-alpha.22",
"@jupyterlab/settingregistry": "^4.0.0-alpha.22",
"@jupyterlab/statedb": "^4.0.0-alpha.22",
"@jupyterlab/translation": "^4.0.0-alpha.22",
"@jupyterlab/ui-components": "^4.0.0-alpha.37",
"@jupyterlab/application": "^4.0.0-beta.0",
"@jupyterlab/apputils": "^4.0.0-beta.0",
"@jupyterlab/codemirror": "^4.0.0-beta.0",
"@jupyterlab/coreutils": "^6.0.0-beta.0",
"@jupyterlab/filebrowser": "^4.0.0-beta.0",
"@jupyterlab/services": "^7.0.0-beta.0",
"@jupyterlab/settingregistry": "^4.0.0-beta.0",
"@jupyterlab/statedb": "^4.0.0-beta.0",
"@jupyterlab/translation": "^4.0.0-beta.0",
"@jupyterlab/ui-components": "^4.0.0-beta.0",
"@lumino/commands": "^2.0.0",
"@lumino/widgets": "^2.0.0",
"y-protocols": "^1.0.5",
"y-websocket": "^1.3.15",
"yjs": "^13.5.40"
},
"devDependencies": {
"@jupyterlab/builder": "^4.0.0-alpha.22",
"@jupyterlab/builder": "^4.0.0-beta.0",
"@types/react": "^18.0.27",
"npm-run-all": "^4.1.5",
"rimraf": "^4.1.2",
123 changes: 93 additions & 30 deletions packages/collaboration-extension/src/filebrowser.ts
Original file line number Diff line number Diff line change
@@ -14,7 +14,13 @@ import { ISettingRegistry } from '@jupyterlab/settingregistry';

import { CommandRegistry } from '@lumino/commands';

import { YDrive } from '@jupyter/docprovider';
import { YFile, YNotebook } from '@jupyter/ydoc';

import {
ICollaborativeDrive,
SharedDocumentFactory,
YDrive
} from '@jupyter/docprovider';

/**
* The command IDs used by the file browser plugin.
@@ -23,13 +29,95 @@ namespace CommandIDs {
export const openPath = 'filebrowser:open-path';
}

/**
* The default file browser factory provider.
*/
export const drive: JupyterFrontEndPlugin<ICollaborativeDrive> = {
id: '@jupyter/collaboration-extension:drive',
provides: ICollaborativeDrive,
requires: [ITranslator],
optional: [],
activate: (
app: JupyterFrontEnd,
translator: ITranslator
): ICollaborativeDrive => {
const trans = translator.load('jupyter_collaboration');
const drive = new YDrive(app.serviceManager.user, trans);
app.serviceManager.contents.addDrive(drive);
return drive;
}
};

/**
* The default file browser factory provider.
*/
export const yfile: JupyterFrontEndPlugin<void> = {
id: '@jupyter/collaboration-extension:yfile',
autoStart: true,
requires: [ICollaborativeDrive],
optional: [],
activate: (app: JupyterFrontEnd, drive: ICollaborativeDrive): void => {
const yFileFactory: SharedDocumentFactory = () => {
return new YFile();
};
drive.sharedModelFactory.registerDocumentFactory('file', yFileFactory);
}
};

/**
* The default file browser factory provider.
*/
export const ynotebook: JupyterFrontEndPlugin<void> = {
id: '@jupyter/collaboration-extension:ynotebook',
autoStart: true,
requires: [ICollaborativeDrive],
optional: [ISettingRegistry],
activate: (
app: JupyterFrontEnd,
drive: ICollaborativeDrive,
settingRegistry: ISettingRegistry | null
): void => {
let disableDocumentWideUndoRedo = true;

// Fetch settings if possible.
if (settingRegistry) {
settingRegistry
.load('@jupyterlab/notebook-extension:tracker')
.then(settings => {
const updateSettings = (settings: ISettingRegistry.ISettings) => {
const enableDocWideUndo = settings?.get(
'experimentalEnableDocumentWideUndoRedo'
).composite as boolean;

disableDocumentWideUndoRedo = !enableDocWideUndo ?? true;
};

updateSettings(settings);
settings.changed.connect((settings: ISettingRegistry.ISettings) =>
updateSettings(settings)
);
});
}

const yNotebookFactory: SharedDocumentFactory = () => {
return new YNotebook({
disableDocumentWideUndoRedo
});
};
drive.sharedModelFactory.registerDocumentFactory(
'notebook',
yNotebookFactory
);
}
};

/**
* The default file browser factory provider.
*/
export const defaultFileBrowser: JupyterFrontEndPlugin<IDefaultFileBrowser> = {
id: '@jupyter/collaboration-extension:defaultFileBrowser',
provides: IDefaultFileBrowser,
requires: [IFileBrowserFactory, ITranslator],
requires: [ICollaborativeDrive, IFileBrowserFactory],
optional: [
IRouter,
JupyterFrontEnd.ITreeResolver,
@@ -38,24 +126,21 @@ export const defaultFileBrowser: JupyterFrontEndPlugin<IDefaultFileBrowser> = {
],
activate: async (
app: JupyterFrontEnd,
drive: ICollaborativeDrive,
fileBrowserFactory: IFileBrowserFactory,
translator: ITranslator,
router: IRouter | null,
tree: JupyterFrontEnd.ITreeResolver | null,
labShell: ILabShell | null,
settingRegistry: ISettingRegistry | null
labShell: ILabShell | null
): Promise<IDefaultFileBrowser> => {
const { commands } = app;

const trans = translator.load('jupyter_collaboration');
const drive = new YDrive(app.serviceManager.user, trans);
app.serviceManager.contents.addDrive(drive);

// Manually restore and load the default file browser.
const defaultBrowser = fileBrowserFactory.createFileBrowser('filebrowser', {
auto: false,
restore: false,
driveName: 'YDrive'
driveName: drive.name
});
void Private.restoreBrowser(
defaultBrowser,
@@ -65,28 +150,6 @@ export const defaultFileBrowser: JupyterFrontEndPlugin<IDefaultFileBrowser> = {
labShell
);

// Fetch settings if possible.
if (settingRegistry) {
settingRegistry
.load('@jupyterlab/notebook-extension:tracker')
.then(settings => {
const updateSettings = (settings: ISettingRegistry.ISettings) => {
const enableDocWideUndo = settings?.get(
'experimentalEnableDocumentWideUndoRedo'
).composite as boolean;

drive.sharedModelFactory.setDocumentOptions('notebook', {
disableDocumentWideUndoRedo: !enableDocWideUndo ?? true
});
};

updateSettings(settings);
settings.changed.connect((settings: ISettingRegistry.ISettings) =>
updateSettings(settings)
);
});
}

return defaultBrowser;
}
};
5 changes: 4 additions & 1 deletion packages/collaboration-extension/src/index.ts
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@

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

import { defaultFileBrowser } from './filebrowser';
import { drive, yfile, ynotebook, defaultFileBrowser } from './filebrowser';
import {
userMenuPlugin,
menuBarPlugin,
@@ -20,6 +20,9 @@ import {
* Export the plugins as default.
*/
const plugins: JupyterFrontEndPlugin<any>[] = [
drive,
yfile,
ynotebook,
defaultFileBrowser,
userMenuPlugin,
menuBarPlugin,
8 changes: 4 additions & 4 deletions packages/collaboration/package.json
Original file line number Diff line number Diff line change
@@ -41,10 +41,10 @@
"dependencies": {
"@codemirror/state": "^6.2.0",
"@codemirror/view": "^6.7.0",
"@jupyterlab/apputils": "^4.0.0-alpha.22",
"@jupyterlab/coreutils": "^6.0.0-alpha.22",
"@jupyterlab/services": "^7.0.0-alpha.22",
"@jupyterlab/ui-components": "^4.0.0-alpha.37",
"@jupyterlab/apputils": "^4.0.0-beta.0",
"@jupyterlab/coreutils": "^6.0.0-beta.0",
"@jupyterlab/services": "^7.0.0-beta.0",
"@jupyterlab/ui-components": "^4.0.0-beta.0",
"@lumino/coreutils": "^2.0.0",
"@lumino/virtualdom": "^2.0.0",
"@lumino/widgets": "^2.0.0",
6 changes: 3 additions & 3 deletions packages/docprovider/package.json
Original file line number Diff line number Diff line change
@@ -42,8 +42,8 @@
},
"dependencies": {
"@jupyter/ydoc": "^0.3.4",
"@jupyterlab/coreutils": "^6.0.0-alpha.22",
"@jupyterlab/services": "^7.0.0-alpha.22",
"@jupyterlab/coreutils": "^6.0.0-beta.0",
"@jupyterlab/services": "^7.0.0-beta.0",
"@lumino/coreutils": "^2.0.0",
"@lumino/disposable": "^2.0.0",
"@lumino/signaling": "^2.0.0",
@@ -52,7 +52,7 @@
"yjs": "^13.5.40"
},
"devDependencies": {
"@jupyterlab/testing": "^4.0.0-alpha.22",
"@jupyterlab/testing": "^4.0.0-beta.0",
"@types/jest": "^29.2.0",
"rimraf": "^4.1.2",
"typescript": "~5.0.2"
1 change: 1 addition & 0 deletions packages/docprovider/src/index.ts
Original file line number Diff line number Diff line change
@@ -9,3 +9,4 @@

export * from './ydrive';
export * from './yprovider';
export * from './tokens';
47 changes: 47 additions & 0 deletions packages/docprovider/src/tokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import { DocumentChange, YDocument } from '@jupyter/ydoc';
import { Contents } from '@jupyterlab/services';
import { Token } from '@lumino/coreutils';

/**
* The collaborative drive.
*/
export const ICollaborativeDrive = new Token<ICollaborativeDrive>(
'@jupyter/collaboration-extension:ICollaborativeDrive'
);

/**
* A document factory for registering shared models
*/
export type SharedDocumentFactory = (
options: Contents.ISharedFactoryOptions
) => YDocument<DocumentChange>;

/**
* A Collaborative implementation for an `IDrive`, talking to the
* server using the Jupyter REST API and a WebSocket connection.
*/
export interface ICollaborativeDrive extends Contents.IDrive {
/**
* SharedModel factory for the YDrive.
*/
readonly sharedModelFactory: ISharedModelFactory;
}

/**
* Yjs sharedModel factory for real-time collaboration.
*/
export interface ISharedModelFactory extends Contents.ISharedFactory {
/**
* Register a SharedDocumentFactory.
*
* @param type Document type
* @param factory Document factory
*/
registerDocumentFactory(
type: Contents.ContentType,
factory: SharedDocumentFactory
): void;
}
Loading