@jupyter/docprovider-extension 5.0.4 → 5.1.0-alpha.1

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,17 @@
3
3
  | Distributed under the terms of the Modified BSD License.
4
4
  |----------------------------------------------------------------------------*/
5
5
  import { ITranslator } from '@jupyterlab/translation';
6
- import { WebSocketProvider, WebSocketAwarenessProvider, IAwarenessProviderFactory, IDocumentProviderFactory } from '@jupyter/docprovider';
6
+ import { WebSocketProvider, ExternalChangeNoticePresenter, WebSocketAwarenessProvider, IAwarenessProviderFactory, IDocumentProviderFactory } from '@jupyter/docprovider';
7
7
  import { URLExt } from '@jupyterlab/coreutils';
8
8
  import { MainAreaWidget, ToolbarButton } from '@jupyterlab/apputils';
9
9
  import { saveIcon, undoIcon } from '@jupyterlab/ui-components';
10
10
  import { IEditorServices } from '@jupyterlab/codeeditor';
11
11
  import { IDocumentManager } from '@jupyterlab/docmanager';
12
12
  import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
13
+ import { ISettingRegistry } from '@jupyterlab/settingregistry';
14
+ import { UUID } from '@lumino/coreutils';
13
15
  import { ConflictDiffWidget } from './conflictDiffWidget';
16
+ import { Widget } from '@lumino/widgets';
14
17
  /**
15
18
  * The plugin ID for settings.
16
19
  */
@@ -20,6 +23,7 @@ const PLUGIN_ID = '@jupyter/docprovider-extension:websocket-provider';
20
23
  */
21
24
  class WebSocketDocumentProviderFactory {
22
25
  constructor(options) {
26
+ this._settings = options.settings;
23
27
  this._trans = options.translator;
24
28
  this._commands = options.commands;
25
29
  this._docManager = options.docManager;
@@ -34,8 +38,9 @@ class WebSocketDocumentProviderFactory {
34
38
  const editorFactory = this._editorFactory;
35
39
  const rendermime = this._rendermime;
36
40
  const path = options.path;
37
- const onConflictShowNotebookDiff = async (localContent) => {
38
- const serverModel = await contents.get(path, { content: true });
41
+ const onConflictShowNotebookDiff = async (localContent, originalPath) => {
42
+ const diffPath = originalPath !== null && originalPath !== void 0 ? originalPath : path;
43
+ const serverModel = await contents.get(diffPath, { content: true });
39
44
  const widget = new ConflictDiffWidget({
40
45
  translator: this._trans,
41
46
  editorFactory,
@@ -46,32 +51,36 @@ class WebSocketDocumentProviderFactory {
46
51
  remote: localContent
47
52
  });
48
53
  const main = new MainAreaWidget({ content: widget });
49
- main.title.label = this._trans.__('Conflict diff: %1', path);
54
+ main.title.label = this._trans.__('Conflict diff: %1', diffPath);
50
55
  main.title.closable = true;
51
- main.toolbar.addItem('revertToRemote', new ToolbarButton({
52
- icon: undoIcon,
53
- label: this._trans.__('Revert to Remote'),
54
- tooltip: this._trans.__('Discard local changes and reload the server version'),
55
- onClick: () => {
56
- var _a;
57
- const context = (_a = this._docManager.findWidget(path)) === null || _a === void 0 ? void 0 : _a.context;
58
- if (context && !context.isDisposed) {
59
- void context.revert();
56
+ // External-change diffs are informational; ordinary conflicts retain
57
+ // their resolution actions.
58
+ if (originalPath === undefined) {
59
+ main.toolbar.addItem('revertToRemote', new ToolbarButton({
60
+ icon: undoIcon,
61
+ label: this._trans.__('Revert to Remote'),
62
+ tooltip: this._trans.__('Discard local changes and reload the server version'),
63
+ onClick: () => {
64
+ var _a;
65
+ const context = (_a = this._docManager.findWidget(path)) === null || _a === void 0 ? void 0 : _a.context;
66
+ if (context && !context.isDisposed) {
67
+ void context.revert();
68
+ }
60
69
  }
61
- }
62
- }));
63
- main.toolbar.addItem('saveLocalAs', new ToolbarButton({
64
- icon: saveIcon,
65
- label: this._trans.__('Save Local As'),
66
- tooltip: this._trans.__('Save the local version with a new name'),
67
- onClick: () => {
68
- var _a;
69
- const context = (_a = this._docManager.findWidget(path)) === null || _a === void 0 ? void 0 : _a.context;
70
- if (context && !context.isDisposed) {
71
- void context.saveAs();
70
+ }));
71
+ main.toolbar.addItem('saveLocalAs', new ToolbarButton({
72
+ icon: saveIcon,
73
+ label: this._trans.__('Save Local As'),
74
+ tooltip: this._trans.__('Save the local version with a new name'),
75
+ onClick: () => {
76
+ var _a;
77
+ const context = (_a = this._docManager.findWidget(path)) === null || _a === void 0 ? void 0 : _a.context;
78
+ if (context && !context.isDisposed) {
79
+ void context.saveAs();
80
+ }
72
81
  }
73
- }
74
- }));
82
+ }));
83
+ }
75
84
  shell.add(main, 'main');
76
85
  shell.activateById(main.id);
77
86
  };
@@ -83,6 +92,58 @@ class WebSocketDocumentProviderFactory {
83
92
  user: options.user,
84
93
  translator: this._trans,
85
94
  serverSettings: options.serverSettings,
95
+ autoReload: () => { var _a; return ((_a = this._settings) === null || _a === void 0 ? void 0 : _a.get('autoReload').composite) === true; },
96
+ showNotice: (notice, beforeSave, createNotice) => ExternalChangeNoticePresenter.forDocument({
97
+ notice,
98
+ beforeSave,
99
+ createNotice,
100
+ shell,
101
+ docManager: this._docManager,
102
+ model: options.model
103
+ }),
104
+ onCloseDocument: () => {
105
+ var _a;
106
+ const views = Array.from(shell.widgets('main')).filter(widget => {
107
+ var _a;
108
+ return ((_a = this._docManager.contextForWidget(widget)) === null || _a === void 0 ? void 0 : _a.model.sharedModel) ===
109
+ options.model;
110
+ });
111
+ const current = shell.currentWidget;
112
+ const view = (_a = views.find(widget => widget === current)) !== null && _a !== void 0 ? _a : views[0];
113
+ view === null || view === void 0 ? void 0 : view.dispose();
114
+ },
115
+ onSwitchDocument: async (newPath) => {
116
+ var _a;
117
+ const views = Array.from(shell.widgets('main')).filter(widget => {
118
+ var _a;
119
+ return ((_a = this._docManager.contextForWidget(widget)) === null || _a === void 0 ? void 0 : _a.model.sharedModel) ===
120
+ options.model;
121
+ });
122
+ const current = shell.currentWidget;
123
+ const view = (_a = views.find(widget => widget === current)) !== null && _a !== void 0 ? _a : views[0];
124
+ if (!view) {
125
+ return;
126
+ }
127
+ // Keep the replacement at this tab's position. Dispose this client's
128
+ // context before opening the same path, so it cannot reuse the old room.
129
+ const placeholder = new Widget();
130
+ placeholder.id = `jp-external-change-${UUID.uuid4()}`;
131
+ placeholder.title.label = view.title.label;
132
+ shell.add(placeholder, 'main', { mode: 'tab-before', ref: view.id });
133
+ const context = this._docManager.contextForWidget(view);
134
+ context === null || context === void 0 ? void 0 : context.dispose();
135
+ views.forEach(widget => widget.dispose());
136
+ try {
137
+ const replacement = this._docManager.open(newPath, options.contentType === 'notebook' ? 'Notebook' : 'Editor', undefined, { mode: 'tab-after', ref: placeholder.id });
138
+ if (!replacement) {
139
+ throw new Error(this._trans.__('Could not open %1', newPath));
140
+ }
141
+ await replacement.context.ready;
142
+ }
143
+ finally {
144
+ placeholder.dispose();
145
+ }
146
+ },
86
147
  onConflictSaveAs: () => this._commands.execute('docmanager:save-as'),
87
148
  onConflictRevert: () => this._commands.execute('docmanager:reload'),
88
149
  // The diff view is notebook-specific (uses nbdime), so only offer it
@@ -119,11 +180,15 @@ export const documentProviderFactoryPlugin = {
119
180
  IRenderMimeRegistry,
120
181
  IDocumentManager
121
182
  ],
122
- optional: [],
183
+ optional: [ISettingRegistry],
123
184
  provides: IDocumentProviderFactory,
124
- activate: async (app, translator, editorServices, rendermime, docManager) => {
185
+ activate: async (app, translator, editorServices, rendermime, docManager, settingRegistry) => {
125
186
  const trans = translator.load('jupyter_collaboration');
187
+ const settings = settingRegistry
188
+ ? await settingRegistry.load(PLUGIN_ID + '-document-factory')
189
+ : null;
126
190
  return new WebSocketDocumentProviderFactory({
191
+ settings,
127
192
  translator: trans,
128
193
  commands: app.commands,
129
194
  docManager,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jupyter/docprovider-extension",
3
- "version": "5.0.4",
3
+ "version": "5.1.0-alpha.1",
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.4",
57
- "@jupyter/docprovider": "^5.0.4",
56
+ "@jupyter/collaborative-drive": "^5.1.0-alpha.1",
57
+ "@jupyter/docprovider": "^5.1.0-alpha.1",
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
+ }