@jupyter/docprovider 1.0.0-alpha.2 → 1.0.0-alpha.4
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/ydrive.d.ts +33 -31
- package/lib/ydrive.js +31 -40
- package/lib/yprovider.js +5 -1
- package/package.json +1 -1
package/lib/ydrive.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DocumentChange, ISharedDocument, YDocument } from '@jupyter/ydoc';
|
|
1
2
|
import { TranslationBundle } from '@jupyterlab/translation';
|
|
2
3
|
import { Contents, Drive, User } from '@jupyterlab/services';
|
|
3
4
|
/**
|
|
@@ -14,18 +15,7 @@ export declare class YDrive extends Drive {
|
|
|
14
15
|
/**
|
|
15
16
|
* SharedModel factory for the YDrive.
|
|
16
17
|
*/
|
|
17
|
-
readonly sharedModelFactory:
|
|
18
|
-
/**
|
|
19
|
-
* Delete a file.
|
|
20
|
-
*
|
|
21
|
-
* @param localPath - The path to the file.
|
|
22
|
-
*
|
|
23
|
-
* @returns A promise which resolves when the file is deleted.
|
|
24
|
-
*
|
|
25
|
-
* #### Notes
|
|
26
|
-
* Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents).
|
|
27
|
-
*/
|
|
28
|
-
delete(localPath: string): Promise<void>;
|
|
18
|
+
readonly sharedModelFactory: SharedModelFactory;
|
|
29
19
|
/**
|
|
30
20
|
* Dispose of the resources held by the manager.
|
|
31
21
|
*/
|
|
@@ -42,20 +32,6 @@ export declare class YDrive extends Drive {
|
|
|
42
32
|
* Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents) and validates the response model.
|
|
43
33
|
*/
|
|
44
34
|
get(localPath: string, options?: Contents.IFetchOptions): Promise<Contents.IModel>;
|
|
45
|
-
/**
|
|
46
|
-
* Rename a file or directory.
|
|
47
|
-
*
|
|
48
|
-
* @param oldLocalPath - The original file path.
|
|
49
|
-
*
|
|
50
|
-
* @param newLocalPath - The new file path.
|
|
51
|
-
*
|
|
52
|
-
* @returns A promise which resolves with the new file contents model when
|
|
53
|
-
* the file is renamed.
|
|
54
|
-
*
|
|
55
|
-
* #### Notes
|
|
56
|
-
* Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents) and validates the response model.
|
|
57
|
-
*/
|
|
58
|
-
rename(oldLocalPath: string, newLocalPath: string): Promise<Contents.IModel>;
|
|
59
35
|
/**
|
|
60
36
|
* Save a file.
|
|
61
37
|
*
|
|
@@ -65,11 +41,6 @@ export declare class YDrive extends Drive {
|
|
|
65
41
|
*
|
|
66
42
|
* @returns A promise which resolves with the file content model when the
|
|
67
43
|
* file is saved.
|
|
68
|
-
*
|
|
69
|
-
* #### Notes
|
|
70
|
-
* Ensure that `model.content` is populated for the file.
|
|
71
|
-
*
|
|
72
|
-
* Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents) and validates the response model.
|
|
73
44
|
*/
|
|
74
45
|
save(localPath: string, options?: Partial<Contents.IModel>): Promise<Contents.IModel>;
|
|
75
46
|
private _onCreate;
|
|
@@ -77,3 +48,34 @@ export declare class YDrive extends Drive {
|
|
|
77
48
|
private _trans;
|
|
78
49
|
private _providers;
|
|
79
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Yjs sharedModel factory for real-time collaboration.
|
|
53
|
+
*/
|
|
54
|
+
declare class SharedModelFactory implements Contents.ISharedFactory {
|
|
55
|
+
private _onCreate;
|
|
56
|
+
private _documentOptions;
|
|
57
|
+
/**
|
|
58
|
+
* Shared model factory constructor
|
|
59
|
+
*
|
|
60
|
+
* @param _onCreate Callback on new document model creation
|
|
61
|
+
*/
|
|
62
|
+
constructor(_onCreate: (options: Contents.ISharedFactoryOptions, sharedModel: YDocument<DocumentChange>) => void);
|
|
63
|
+
/**
|
|
64
|
+
* Whether the IDrive supports real-time collaboration or not.
|
|
65
|
+
*/
|
|
66
|
+
readonly collaborative = true;
|
|
67
|
+
/**
|
|
68
|
+
* Set shared document model options
|
|
69
|
+
*
|
|
70
|
+
* @param type Document type
|
|
71
|
+
* @param value Document options
|
|
72
|
+
*/
|
|
73
|
+
setDocumentOptions(type: Contents.ContentType, value: Record<string, any>): void;
|
|
74
|
+
/**
|
|
75
|
+
* Create a new `ISharedDocument` instance.
|
|
76
|
+
*
|
|
77
|
+
* It should return `undefined` if the factory is not able to create a `ISharedDocument`.
|
|
78
|
+
*/
|
|
79
|
+
createNew(options: Contents.ISharedFactoryOptions): ISharedDocument | undefined;
|
|
80
|
+
}
|
|
81
|
+
export {};
|
package/lib/ydrive.js
CHANGED
|
@@ -55,22 +55,6 @@ export class YDrive extends Drive {
|
|
|
55
55
|
this._providers = new Map();
|
|
56
56
|
this.sharedModelFactory = new SharedModelFactory(this._onCreate);
|
|
57
57
|
}
|
|
58
|
-
/**
|
|
59
|
-
* Delete a file.
|
|
60
|
-
*
|
|
61
|
-
* @param localPath - The path to the file.
|
|
62
|
-
*
|
|
63
|
-
* @returns A promise which resolves when the file is deleted.
|
|
64
|
-
*
|
|
65
|
-
* #### Notes
|
|
66
|
-
* Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents).
|
|
67
|
-
*/
|
|
68
|
-
async delete(localPath) {
|
|
69
|
-
await super.delete(localPath);
|
|
70
|
-
// FIXME
|
|
71
|
-
// We are not removing the path from `sharedPaths` as multiple providers of the same file (with different model) may exist.
|
|
72
|
-
//this._sharedPaths.delete(localPath);
|
|
73
|
-
}
|
|
74
58
|
/**
|
|
75
59
|
* Dispose of the resources held by the manager.
|
|
76
60
|
*/
|
|
@@ -105,22 +89,6 @@ export class YDrive extends Drive {
|
|
|
105
89
|
}
|
|
106
90
|
return super.get(localPath, options);
|
|
107
91
|
}
|
|
108
|
-
/**
|
|
109
|
-
* Rename a file or directory.
|
|
110
|
-
*
|
|
111
|
-
* @param oldLocalPath - The original file path.
|
|
112
|
-
*
|
|
113
|
-
* @param newLocalPath - The new file path.
|
|
114
|
-
*
|
|
115
|
-
* @returns A promise which resolves with the new file contents model when
|
|
116
|
-
* the file is renamed.
|
|
117
|
-
*
|
|
118
|
-
* #### Notes
|
|
119
|
-
* Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents) and validates the response model.
|
|
120
|
-
*/
|
|
121
|
-
async rename(oldLocalPath, newLocalPath) {
|
|
122
|
-
return await super.rename(oldLocalPath, newLocalPath);
|
|
123
|
-
}
|
|
124
92
|
/**
|
|
125
93
|
* Save a file.
|
|
126
94
|
*
|
|
@@ -130,27 +98,48 @@ export class YDrive extends Drive {
|
|
|
130
98
|
*
|
|
131
99
|
* @returns A promise which resolves with the file content model when the
|
|
132
100
|
* file is saved.
|
|
133
|
-
*
|
|
134
|
-
* #### Notes
|
|
135
|
-
* Ensure that `model.content` is populated for the file.
|
|
136
|
-
*
|
|
137
|
-
* Uses the [Jupyter Notebook API](http://petstore.swagger.io/?url=https://raw.githubusercontent.com/jupyter/notebook/master/notebook/services/api/api.yaml#!/contents) and validates the response model.
|
|
138
101
|
*/
|
|
139
102
|
async save(localPath, options = {}) {
|
|
140
|
-
//
|
|
141
|
-
|
|
103
|
+
// Check that there is a provider - it won't e.g. if the document model is not collaborative.
|
|
104
|
+
if (options.format && options.type) {
|
|
105
|
+
const key = `${options.format}:${options.type}:${localPath}`;
|
|
106
|
+
const provider = this._providers.get(key);
|
|
107
|
+
if (provider) {
|
|
108
|
+
// Save is done from the backend
|
|
109
|
+
return this.get(localPath, { ...options, content: false });
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return super.save(localPath, options);
|
|
142
113
|
}
|
|
143
114
|
}
|
|
144
115
|
/**
|
|
145
116
|
* Yjs sharedModel factory for real-time collaboration.
|
|
146
117
|
*/
|
|
147
118
|
class SharedModelFactory {
|
|
119
|
+
/**
|
|
120
|
+
* Shared model factory constructor
|
|
121
|
+
*
|
|
122
|
+
* @param _onCreate Callback on new document model creation
|
|
123
|
+
*/
|
|
148
124
|
constructor(_onCreate) {
|
|
149
125
|
this._onCreate = _onCreate;
|
|
150
126
|
/**
|
|
151
127
|
* Whether the IDrive supports real-time collaboration or not.
|
|
152
128
|
*/
|
|
153
129
|
this.collaborative = true;
|
|
130
|
+
this._documentOptions = new Map();
|
|
131
|
+
this._documentOptions.set('notebook', {
|
|
132
|
+
disableDocumentWideUndoRedo: true
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Set shared document model options
|
|
137
|
+
*
|
|
138
|
+
* @param type Document type
|
|
139
|
+
* @param value Document options
|
|
140
|
+
*/
|
|
141
|
+
setDocumentOptions(type, value) {
|
|
142
|
+
this._documentOptions.set(type, { ...value });
|
|
154
143
|
}
|
|
155
144
|
/**
|
|
156
145
|
* Create a new `ISharedDocument` instance.
|
|
@@ -163,6 +152,8 @@ class SharedModelFactory {
|
|
|
163
152
|
return;
|
|
164
153
|
}
|
|
165
154
|
if (!options.collaborative) {
|
|
155
|
+
// Bail if the document model does not support collaboration
|
|
156
|
+
// the `sharedModel` will be the default one.
|
|
166
157
|
return;
|
|
167
158
|
}
|
|
168
159
|
let sharedModel;
|
|
@@ -171,7 +162,7 @@ class SharedModelFactory {
|
|
|
171
162
|
sharedModel = new YFile();
|
|
172
163
|
break;
|
|
173
164
|
case 'notebook':
|
|
174
|
-
sharedModel = new YNotebook();
|
|
165
|
+
sharedModel = new YNotebook(this._documentOptions.get('notebook'));
|
|
175
166
|
break;
|
|
176
167
|
//default:
|
|
177
168
|
// FIXME we should request a registry for the proper sharedModel
|
package/lib/yprovider.js
CHANGED
|
@@ -24,7 +24,11 @@ export class WebSocketProvider {
|
|
|
24
24
|
if (event.code === 1003) {
|
|
25
25
|
console.error('Document provider closed:', event.reason);
|
|
26
26
|
showErrorMessage(this._trans.__('Session expired'), this._trans.__('The document session expired. You need to reload this browser tab.'), [Dialog.okButton({ label: this._trans.__('Reload') })])
|
|
27
|
-
.then(r =>
|
|
27
|
+
.then((r) => {
|
|
28
|
+
if (r.button.accept) {
|
|
29
|
+
window.location.reload();
|
|
30
|
+
}
|
|
31
|
+
})
|
|
28
32
|
.catch(e => window.location.reload());
|
|
29
33
|
// Dispose shared model immediately. Better break the document model,
|
|
30
34
|
// than overriding data on disk.
|