@jupyter/docprovider-extension 5.0.3 → 5.1.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/yprovider.js
CHANGED
|
@@ -3,14 +3,18 @@
|
|
|
3
3
|
| Distributed under the terms of the Modified BSD License.
|
|
4
4
|
|----------------------------------------------------------------------------*/
|
|
5
5
|
import { ITranslator } from '@jupyterlab/translation';
|
|
6
|
-
import {
|
|
6
|
+
import { ILabShell } from '@jupyterlab/application';
|
|
7
|
+
import { WebSocketProvider, ExternalChangeNoticePresenter, WebSocketAwarenessProvider, IAwarenessProviderFactory, IDocumentProviderFactory } from '@jupyter/docprovider';
|
|
7
8
|
import { URLExt } from '@jupyterlab/coreutils';
|
|
8
9
|
import { MainAreaWidget, ToolbarButton } from '@jupyterlab/apputils';
|
|
9
10
|
import { saveIcon, undoIcon } from '@jupyterlab/ui-components';
|
|
10
11
|
import { IEditorServices } from '@jupyterlab/codeeditor';
|
|
11
12
|
import { IDocumentManager } from '@jupyterlab/docmanager';
|
|
12
13
|
import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
|
|
14
|
+
import { ISettingRegistry } from '@jupyterlab/settingregistry';
|
|
15
|
+
import { UUID } from '@lumino/coreutils';
|
|
13
16
|
import { ConflictDiffWidget } from './conflictDiffWidget';
|
|
17
|
+
import { Widget } from '@lumino/widgets';
|
|
14
18
|
/**
|
|
15
19
|
* The plugin ID for settings.
|
|
16
20
|
*/
|
|
@@ -20,6 +24,14 @@ const PLUGIN_ID = '@jupyter/docprovider-extension:websocket-provider';
|
|
|
20
24
|
*/
|
|
21
25
|
class WebSocketDocumentProviderFactory {
|
|
22
26
|
constructor(options) {
|
|
27
|
+
this._viewSignals = [];
|
|
28
|
+
if (options.shell.currentChanged) {
|
|
29
|
+
this._viewSignals.push(options.shell.currentChanged);
|
|
30
|
+
}
|
|
31
|
+
if (options.labShell) {
|
|
32
|
+
this._viewSignals.push(options.labShell.layoutModified);
|
|
33
|
+
}
|
|
34
|
+
this._settings = options.settings;
|
|
23
35
|
this._trans = options.translator;
|
|
24
36
|
this._commands = options.commands;
|
|
25
37
|
this._docManager = options.docManager;
|
|
@@ -34,8 +46,9 @@ class WebSocketDocumentProviderFactory {
|
|
|
34
46
|
const editorFactory = this._editorFactory;
|
|
35
47
|
const rendermime = this._rendermime;
|
|
36
48
|
const path = options.path;
|
|
37
|
-
const onConflictShowNotebookDiff = async (localContent) => {
|
|
38
|
-
const
|
|
49
|
+
const onConflictShowNotebookDiff = async (localContent, originalPath) => {
|
|
50
|
+
const diffPath = originalPath !== null && originalPath !== void 0 ? originalPath : path;
|
|
51
|
+
const serverModel = await contents.get(diffPath, { content: true });
|
|
39
52
|
const widget = new ConflictDiffWidget({
|
|
40
53
|
translator: this._trans,
|
|
41
54
|
editorFactory,
|
|
@@ -46,32 +59,36 @@ class WebSocketDocumentProviderFactory {
|
|
|
46
59
|
remote: localContent
|
|
47
60
|
});
|
|
48
61
|
const main = new MainAreaWidget({ content: widget });
|
|
49
|
-
main.title.label = this._trans.__('Conflict diff: %1',
|
|
62
|
+
main.title.label = this._trans.__('Conflict diff: %1', diffPath);
|
|
50
63
|
main.title.closable = true;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
64
|
+
// External-change diffs are informational; ordinary conflicts retain
|
|
65
|
+
// their resolution actions.
|
|
66
|
+
if (originalPath === undefined) {
|
|
67
|
+
main.toolbar.addItem('revertToRemote', new ToolbarButton({
|
|
68
|
+
icon: undoIcon,
|
|
69
|
+
label: this._trans.__('Revert to Remote'),
|
|
70
|
+
tooltip: this._trans.__('Discard local changes and reload the server version'),
|
|
71
|
+
onClick: () => {
|
|
72
|
+
var _a;
|
|
73
|
+
const context = (_a = this._docManager.findWidget(path)) === null || _a === void 0 ? void 0 : _a.context;
|
|
74
|
+
if (context && !context.isDisposed) {
|
|
75
|
+
void context.revert();
|
|
76
|
+
}
|
|
60
77
|
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
78
|
+
}));
|
|
79
|
+
main.toolbar.addItem('saveLocalAs', new ToolbarButton({
|
|
80
|
+
icon: saveIcon,
|
|
81
|
+
label: this._trans.__('Save Local As'),
|
|
82
|
+
tooltip: this._trans.__('Save the local version with a new name'),
|
|
83
|
+
onClick: () => {
|
|
84
|
+
var _a;
|
|
85
|
+
const context = (_a = this._docManager.findWidget(path)) === null || _a === void 0 ? void 0 : _a.context;
|
|
86
|
+
if (context && !context.isDisposed) {
|
|
87
|
+
void context.saveAs();
|
|
88
|
+
}
|
|
72
89
|
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
75
92
|
shell.add(main, 'main');
|
|
76
93
|
shell.activateById(main.id);
|
|
77
94
|
};
|
|
@@ -83,6 +100,63 @@ class WebSocketDocumentProviderFactory {
|
|
|
83
100
|
user: options.user,
|
|
84
101
|
translator: this._trans,
|
|
85
102
|
serverSettings: options.serverSettings,
|
|
103
|
+
autoReload: () => { var _a; return ((_a = this._settings) === null || _a === void 0 ? void 0 : _a.get('autoReload').composite) === true; },
|
|
104
|
+
showNotice: (notice, beforeSave, createNotice) => new ExternalChangeNoticePresenter({
|
|
105
|
+
notice,
|
|
106
|
+
beforeSave,
|
|
107
|
+
createNotice,
|
|
108
|
+
views: () => shell.widgets('main'),
|
|
109
|
+
viewSignals: this._viewSignals,
|
|
110
|
+
contextForWidget: view => {
|
|
111
|
+
const context = this._docManager.contextForWidget(view);
|
|
112
|
+
return (context === null || context === void 0 ? void 0 : context.model.sharedModel) === options.model
|
|
113
|
+
? context
|
|
114
|
+
: undefined;
|
|
115
|
+
}
|
|
116
|
+
}),
|
|
117
|
+
onCloseDocument: () => {
|
|
118
|
+
var _a;
|
|
119
|
+
const views = Array.from(shell.widgets('main')).filter(widget => {
|
|
120
|
+
var _a;
|
|
121
|
+
return ((_a = this._docManager.contextForWidget(widget)) === null || _a === void 0 ? void 0 : _a.model.sharedModel) ===
|
|
122
|
+
options.model;
|
|
123
|
+
});
|
|
124
|
+
const current = shell.currentWidget;
|
|
125
|
+
const view = (_a = views.find(widget => widget === current)) !== null && _a !== void 0 ? _a : views[0];
|
|
126
|
+
view === null || view === void 0 ? void 0 : view.dispose();
|
|
127
|
+
},
|
|
128
|
+
onSwitchDocument: async (newPath) => {
|
|
129
|
+
var _a;
|
|
130
|
+
const views = Array.from(shell.widgets('main')).filter(widget => {
|
|
131
|
+
var _a;
|
|
132
|
+
return ((_a = this._docManager.contextForWidget(widget)) === null || _a === void 0 ? void 0 : _a.model.sharedModel) ===
|
|
133
|
+
options.model;
|
|
134
|
+
});
|
|
135
|
+
const current = shell.currentWidget;
|
|
136
|
+
const view = (_a = views.find(widget => widget === current)) !== null && _a !== void 0 ? _a : views[0];
|
|
137
|
+
if (!view) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
// Keep the replacement at this tab's position. Dispose this client's
|
|
141
|
+
// context before opening the same path, so it cannot reuse the old room.
|
|
142
|
+
const placeholder = new Widget();
|
|
143
|
+
placeholder.id = `jp-external-change-${UUID.uuid4()}`;
|
|
144
|
+
placeholder.title.label = view.title.label;
|
|
145
|
+
shell.add(placeholder, 'main', { mode: 'tab-before', ref: view.id });
|
|
146
|
+
const context = this._docManager.contextForWidget(view);
|
|
147
|
+
context === null || context === void 0 ? void 0 : context.dispose();
|
|
148
|
+
views.forEach(widget => widget.dispose());
|
|
149
|
+
try {
|
|
150
|
+
const replacement = this._docManager.open(newPath, options.contentType === 'notebook' ? 'Notebook' : 'Editor', undefined, { mode: 'tab-after', ref: placeholder.id });
|
|
151
|
+
if (!replacement) {
|
|
152
|
+
throw new Error(this._trans.__('Could not open %1', newPath));
|
|
153
|
+
}
|
|
154
|
+
await replacement.context.ready;
|
|
155
|
+
}
|
|
156
|
+
finally {
|
|
157
|
+
placeholder.dispose();
|
|
158
|
+
}
|
|
159
|
+
},
|
|
86
160
|
onConflictSaveAs: () => this._commands.execute('docmanager:save-as'),
|
|
87
161
|
onConflictRevert: () => this._commands.execute('docmanager:reload'),
|
|
88
162
|
// The diff view is notebook-specific (uses nbdime), so only offer it
|
|
@@ -119,11 +193,16 @@ export const documentProviderFactoryPlugin = {
|
|
|
119
193
|
IRenderMimeRegistry,
|
|
120
194
|
IDocumentManager
|
|
121
195
|
],
|
|
122
|
-
optional: [],
|
|
196
|
+
optional: [ISettingRegistry, ILabShell],
|
|
123
197
|
provides: IDocumentProviderFactory,
|
|
124
|
-
activate: async (app, translator, editorServices, rendermime, docManager) => {
|
|
198
|
+
activate: async (app, translator, editorServices, rendermime, docManager, settingRegistry, labShell) => {
|
|
125
199
|
const trans = translator.load('jupyter_collaboration');
|
|
200
|
+
const settings = settingRegistry
|
|
201
|
+
? await settingRegistry.load(PLUGIN_ID + '-document-factory')
|
|
202
|
+
: null;
|
|
126
203
|
return new WebSocketDocumentProviderFactory({
|
|
204
|
+
labShell,
|
|
205
|
+
settings,
|
|
127
206
|
translator: trans,
|
|
128
207
|
commands: app.commands,
|
|
129
208
|
docManager,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jupyter/docprovider-extension",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.1.0-alpha.0",
|
|
4
4
|
"description": "JupyterLab - Collaborative Shared Models",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"jupyter",
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
"watch:labextension": "jupyter-builder watch ."
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@jupyter/collaborative-drive": "^5.0.
|
|
57
|
-
"@jupyter/docprovider": "^5.0.
|
|
56
|
+
"@jupyter/collaborative-drive": "^5.1.0-alpha.0",
|
|
57
|
+
"@jupyter/docprovider": "^5.1.0-alpha.0",
|
|
58
58
|
"@jupyter/ydoc": "^4.0.0",
|
|
59
59
|
"@jupyterlab/application": "^4.6.0",
|
|
60
60
|
"@jupyterlab/apputils": "^4.7.0",
|
|
@@ -132,6 +132,7 @@
|
|
|
132
132
|
"bundled": false,
|
|
133
133
|
"singleton": true
|
|
134
134
|
}
|
|
135
|
-
}
|
|
135
|
+
},
|
|
136
|
+
"schemaDir": "schema"
|
|
136
137
|
}
|
|
137
138
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"title": "Collaborative documents",
|
|
3
|
+
"description": "Settings for external changes to collaborative documents.",
|
|
4
|
+
"type": "object",
|
|
5
|
+
"properties": {
|
|
6
|
+
"autoReload": {
|
|
7
|
+
"title": "Automatically load files changed on disk",
|
|
8
|
+
"description": "Replace current editor content with the disk version without asking when a file changes externally.",
|
|
9
|
+
"type": "boolean",
|
|
10
|
+
"default": false
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"additionalProperties": false
|
|
14
|
+
}
|