Skip to content

Commit d035a80

Browse files
committed
Support suggestions
1 parent b3e189e commit d035a80

File tree

11 files changed

+224
-24
lines changed

11 files changed

+224
-24
lines changed

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,9 @@
6565
"stylelint-prettier": "^3.0.0",
6666
"typedoc": "~0.23.28",
6767
"typescript": "~5.0.4"
68+
},
69+
"resolutions": {
70+
"@jupyter/ydoc": "file:.yalc/@jupyter/ydoc",
71+
"@jupyterlab/services": "file:.yalc/@jupyterlab/services"
6872
}
6973
}

packages/collaboration-extension/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"dependencies": {
5656
"@jupyter/collaboration": "^2.0.2",
5757
"@jupyter/docprovider": "^2.0.2",
58-
"@jupyter/ydoc": "^1.1.0-a0",
58+
"@jupyter/ydoc": "file:.yalc/@jupyter/ydoc",
5959
"@jupyterlab/application": "^4.0.5",
6060
"@jupyterlab/apputils": "^4.0.5",
6161
"@jupyterlab/codemirror": "^4.0.5",

packages/collaboration-extension/src/collaboration.ts

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@
55
* @module collaboration-extension
66
*/
77

8+
import {
9+
DocumentRegistry
10+
} from '@jupyterlab/docregistry';
11+
12+
import {
13+
NotebookPanel, INotebookModel
14+
} from '@jupyterlab/notebook';
15+
16+
import {
17+
IDisposable, DisposableDelegate
18+
} from '@lumino/disposable';
19+
20+
import { CommandRegistry } from '@lumino/commands';
21+
822
import {
923
JupyterFrontEnd,
1024
JupyterFrontEndPlugin
@@ -15,7 +29,11 @@ import {
1529
IEditorExtensionRegistry
1630
} from '@jupyterlab/codemirror';
1731
import { WebSocketAwarenessProvider } from '@jupyter/docprovider';
18-
import { SidePanel, usersIcon } from '@jupyterlab/ui-components';
32+
import {
33+
SidePanel,
34+
usersIcon,
35+
caretDownIcon
36+
} from '@jupyterlab/ui-components';
1937
import { URLExt } from '@jupyterlab/coreutils';
2038
import { ServerConnection } from '@jupyterlab/services';
2139
import { IStateDB, StateDB } from '@jupyterlab/statedb';
@@ -189,3 +207,61 @@ export const userEditorCursors: JupyterFrontEndPlugin<void> = {
189207
});
190208
}
191209
};
210+
211+
/**
212+
* A plugin to add editing mode to the notebook page
213+
*/
214+
export const editingMode: JupyterFrontEndPlugin<void> = {
215+
id: '@jupyter/collaboration-extension:editingMode',
216+
description: 'A plugin to add editing mode to the notebook page.',
217+
autoStart: true,
218+
requires: [ITranslator],
219+
activate: (
220+
app: JupyterFrontEnd,
221+
) => {
222+
app.docRegistry.addWidgetExtension('Notebook', new EditingModeExtension());
223+
},
224+
};
225+
226+
export class EditingModeExtension implements DocumentRegistry.IWidgetExtension<NotebookPanel, INotebookModel> {
227+
createNew(panel: NotebookPanel, context: DocumentRegistry.IContext<INotebookModel>): IDisposable {
228+
const menubar = new MenuBar();
229+
const commands = new CommandRegistry();
230+
const menu = new Menu({ commands });
231+
menu.title.label = 'Editing';
232+
menu.title.icon = caretDownIcon;
233+
addMenuItem(commands, menu, 'editing', 'Editing', context);
234+
addMenuItem(commands, menu, 'suggesting', 'Suggesting', context);
235+
menubar.addMenu(menu);
236+
237+
panel.toolbar.insertItem(990, 'editingMode', menubar);
238+
return new DisposableDelegate(() => {
239+
menubar.dispose();
240+
});
241+
}
242+
}
243+
244+
/**
245+
* Helper Function to add menu items.
246+
*/
247+
function addMenuItem(
248+
commands: CommandRegistry,
249+
menu: Menu,
250+
command: string,
251+
label: string,
252+
context: DocumentRegistry.IContext<INotebookModel>,
253+
): void {
254+
commands.addCommand(command, {
255+
label: label,
256+
execute: () => {
257+
menu.title.label = label;
258+
if (command == 'suggesting') {
259+
context.model.sharedModel.getProvider('root').fork();
260+
}
261+
}
262+
});
263+
menu.addItem({
264+
type: 'command',
265+
command: command
266+
});
267+
}

packages/collaboration-extension/src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import {
1919
menuBarPlugin,
2020
rtcGlobalAwarenessPlugin,
2121
rtcPanelPlugin,
22-
userEditorCursors
22+
userEditorCursors,
23+
editingMode
2324
} from './collaboration';
2425
import { sharedLink } from './sharedlink';
2526

@@ -37,7 +38,8 @@ const plugins: JupyterFrontEndPlugin<any>[] = [
3738
rtcGlobalAwarenessPlugin,
3839
rtcPanelPlugin,
3940
sharedLink,
40-
userEditorCursors
41+
userEditorCursors,
42+
editingMode
4143
];
4244

4345
export default plugins;

packages/collaboration/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"@codemirror/state": "^6.2.0",
4343
"@codemirror/view": "^6.7.0",
4444
"@jupyter/docprovider": "^2.0.2",
45+
"@jupyter/ydoc": "file:.yalc/@jupyter/ydoc",
4546
"@jupyterlab/apputils": "^4.0.5",
4647
"@jupyterlab/coreutils": "^6.0.5",
4748
"@jupyterlab/services": "^7.0.5",

packages/collaboration/style/base.css

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,22 @@
99
.jp-shared-link-body {
1010
user-select: none;
1111
}
12+
13+
.jp-EditingMode {
14+
display: flex;
15+
flex-direction: column;
16+
align-items: center;
17+
justify-content: center;
18+
}
19+
20+
.jp-EditingMode .lm-MenuBar-itemIcon svg {
21+
vertical-align: sub;
22+
}
23+
24+
.jp-nb-editing-mode-button > .jp-ToolbarButtonComponent::part(content) {
25+
flex-direction: row-reverse;
26+
}
27+
28+
.jp-nb-editing-mode-button > .jp-ToolbarButtonComponent > svg {
29+
padding-left: 3px;
30+
}

packages/docprovider/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"watch": "tsc -b --watch"
4242
},
4343
"dependencies": {
44-
"@jupyter/ydoc": "^1.1.0-a0",
44+
"@jupyter/ydoc": "file:.yalc/@jupyter/ydoc",
4545
"@jupyterlab/coreutils": "^6.0.5",
4646
"@jupyterlab/services": "^7.0.5",
4747
"@lumino/coreutils": "^2.1.0",
@@ -51,6 +51,10 @@
5151
"y-websocket": "^1.3.15",
5252
"yjs": "^13.5.40"
5353
},
54+
"resolutions": {
55+
"@jupyterlab/services": "file:.yalc/@jupyterlab/services",
56+
"@jupyter/ydoc": "file:.yalc/@jupyter/ydoc"
57+
},
5458
"devDependencies": {
5559
"@jupyterlab/testing": "^4.0.5",
5660
"@types/jest": "^29.2.0",

packages/docprovider/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
export * from './awareness';
11+
export * from './requests';
1112
export * from './ydrive';
1213
export * from './yprovider';
1314
export * from './tokens';

packages/docprovider/src/requests.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { ServerConnection, Contents } from '@jupyterlab/services';
1111
* See https://github.com/jupyterlab/jupyter_collaboration
1212
*/
1313
const DOC_SESSION_URL = 'api/collaboration/session';
14+
const DOC_FORK_URL = 'api/collaboration/fork_room';
1415

1516
/**
1617
* Document session model
@@ -73,3 +74,42 @@ export async function requestDocSession(
7374

7475
return data;
7576
}
77+
78+
79+
export async function requestDocFork(
80+
roomid: string,
81+
): Promise<any> {
82+
const settings = ServerConnection.makeSettings();
83+
const url = URLExt.join(
84+
settings.baseUrl,
85+
DOC_FORK_URL,
86+
encodeURIComponent(roomid)
87+
);
88+
const body = {
89+
method: 'PUT',
90+
body: JSON.stringify({ roomid })
91+
};
92+
93+
let response: Response;
94+
try {
95+
response = await ServerConnection.makeRequest(url, body, settings);
96+
} catch (error) {
97+
throw new ServerConnection.NetworkError(error as Error);
98+
}
99+
100+
let data: any = await response.text();
101+
102+
if (data.length > 0) {
103+
try {
104+
data = JSON.parse(data);
105+
} catch (error) {
106+
console.log('Not a JSON response body.', response);
107+
}
108+
}
109+
110+
if (!response.ok) {
111+
throw new ServerConnection.ResponseError(response, data.message || data);
112+
}
113+
114+
return data;
115+
}

packages/docprovider/src/ydrive.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ export class YDrive extends Drive implements ICollaborativeDrive {
147147
const key = `${options.format}:${options.contentType}:${options.path}`;
148148
this._providers.set(key, provider);
149149

150+
sharedModel.setProvider('root', provider);
150151
sharedModel.disposed.connect(() => {
151152
const provider = this._providers.get(key);
152153
if (provider) {

0 commit comments

Comments
 (0)