@jupyter/docprovider 4.0.2 → 4.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/ydrive.d.ts CHANGED
@@ -3,6 +3,7 @@ import { Contents, IContentProvider, RestContentProvider, User } from '@jupyterl
3
3
  import { ISignal } from '@lumino/signaling';
4
4
  import { IDocumentProvider, ISharedModelFactory } from '@jupyter/collaborative-drive';
5
5
  import { Awareness } from 'y-protocols/awareness';
6
+ import { ISettingRegistry } from '@jupyterlab/settingregistry';
6
7
  export interface IForkProvider {
7
8
  connectToForkDoc: (forkRoomId: string, sessionId: string) => Promise<void>;
8
9
  reconnect: () => Promise<void>;
@@ -14,6 +15,7 @@ declare namespace RtcContentProvider {
14
15
  user: User.IManager;
15
16
  trans: TranslationBundle;
16
17
  globalAwareness: Awareness | null;
18
+ docmanagerSettings: ISettingRegistry.ISettings | null;
17
19
  }
18
20
  }
19
21
  export declare class RtcContentProvider extends RestContentProvider implements IContentProvider {
@@ -55,5 +57,6 @@ export declare class RtcContentProvider extends RestContentProvider implements I
55
57
  private _providers;
56
58
  private _ydriveFileChanged;
57
59
  private _serverSettings;
60
+ private _docmanagerSettings;
58
61
  }
59
62
  export {};
package/lib/ydrive.js CHANGED
@@ -4,7 +4,15 @@ import { PageConfig, URLExt } from '@jupyterlab/coreutils';
4
4
  import { RestContentProvider } from '@jupyterlab/services';
5
5
  import { Signal } from '@lumino/signaling';
6
6
  import { WebSocketProvider } from './yprovider';
7
+ import * as encoding from 'lib0/encoding';
7
8
  const DISABLE_RTC = PageConfig.getOption('disableRTC') === 'true' ? true : false;
9
+ const RAW_MESSAGE_TYPE = 2;
10
+ const SAVE_MESSAGE = (() => {
11
+ const encoder = encoding.createEncoder();
12
+ encoding.writeVarUint(encoder, RAW_MESSAGE_TYPE);
13
+ encoding.writeVarString(encoder, 'save');
14
+ return encoding.toUint8Array(encoder);
15
+ })();
8
16
  /**
9
17
  * The url for the default drive service.
10
18
  */
@@ -13,10 +21,19 @@ export class RtcContentProvider extends RestContentProvider {
13
21
  constructor(options) {
14
22
  super(options);
15
23
  this._onCreate = (options, sharedModel) => {
16
- var _a, _b;
24
+ var _a, _b, _c, _d, _e, _f;
17
25
  if (typeof options.format !== 'string') {
18
26
  return;
19
27
  }
28
+ // Set initial autosave value, used to determine backend autosave (default: true)
29
+ const autosave = (_c = (_b = (_a = this._docmanagerSettings) === null || _a === void 0 ? void 0 : _a.composite) === null || _b === void 0 ? void 0 : _b['autosave']) !== null && _c !== void 0 ? _c : true;
30
+ sharedModel.awareness.setLocalStateField('autosave', autosave);
31
+ // Watch for changes in settings
32
+ (_d = this._docmanagerSettings) === null || _d === void 0 ? void 0 : _d.changed.connect(() => {
33
+ var _a, _b, _c;
34
+ const newAutosave = (_c = (_b = (_a = this._docmanagerSettings) === null || _a === void 0 ? void 0 : _a.composite) === null || _b === void 0 ? void 0 : _b['autosave']) !== null && _c !== void 0 ? _c : true;
35
+ sharedModel.awareness.setLocalStateField('autosave', newAutosave);
36
+ });
20
37
  try {
21
38
  const provider = new WebSocketProvider({
22
39
  url: URLExt.join(this._serverSettings.wsUrl, DOCUMENT_PROVIDER_URL),
@@ -28,11 +45,11 @@ export class RtcContentProvider extends RestContentProvider {
28
45
  translator: this._trans
29
46
  });
30
47
  // Add the document path in the list of opened ones for this user.
31
- const state = ((_a = this._globalAwareness) === null || _a === void 0 ? void 0 : _a.getLocalState()) || {};
48
+ const state = ((_e = this._globalAwareness) === null || _e === void 0 ? void 0 : _e.getLocalState()) || {};
32
49
  const documents = state.documents || [];
33
50
  if (!documents.includes(options.path)) {
34
51
  documents.push(options.path);
35
- (_b = this._globalAwareness) === null || _b === void 0 ? void 0 : _b.setLocalStateField('documents', documents);
52
+ (_f = this._globalAwareness) === null || _f === void 0 ? void 0 : _f.setLocalStateField('documents', documents);
36
53
  }
37
54
  const key = `${options.format}:${options.contentType}:${options.path}`;
38
55
  this._providers.set(key, provider);
@@ -92,6 +109,7 @@ export class RtcContentProvider extends RestContentProvider {
92
109
  this._serverSettings = options.serverSettings;
93
110
  this.sharedModelFactory = new SharedModelFactory(this._onCreate);
94
111
  this._providers = new Map();
112
+ this._docmanagerSettings = options.docmanagerSettings;
95
113
  }
96
114
  get providers() {
97
115
  return this._providers;
@@ -136,12 +154,13 @@ export class RtcContentProvider extends RestContentProvider {
136
154
  * file is saved.
137
155
  */
138
156
  async save(localPath, options = {}) {
157
+ var _a, _b;
139
158
  // Check that there is a provider - it won't e.g. if the document model is not collaborative.
140
159
  if (options.format && options.type) {
141
160
  const key = `${options.format}:${options.type}:${localPath}`;
142
161
  const provider = this._providers.get(key);
143
162
  if (provider) {
144
- // Save is done from the backend
163
+ (_b = (_a = provider.wsProvider) === null || _a === void 0 ? void 0 : _a.ws) === null || _b === void 0 ? void 0 : _b.send(SAVE_MESSAGE);
145
164
  const fetchOptions = {
146
165
  type: options.type,
147
166
  format: options.format,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jupyter/docprovider",
3
- "version": "4.0.2",
3
+ "version": "4.1.0-alpha.0",
4
4
  "description": "JupyterLab - Document Provider",
5
5
  "homepage": "https://github.com/jupyterlab/jupyter-collaboration",
6
6
  "bugs": {
@@ -41,7 +41,7 @@
41
41
  "watch": "tsc -b --watch"
42
42
  },
43
43
  "dependencies": {
44
- "@jupyter/collaborative-drive": "^4.0.2",
44
+ "@jupyter/collaborative-drive": "^4.1.0-alpha.0",
45
45
  "@jupyter/ydoc": "^2.1.3 || ^3.0.0",
46
46
  "@jupyterlab/apputils": "^4.4.0",
47
47
  "@jupyterlab/cells": "^4.4.0",