@jupyter/docprovider 3.0.0-beta.1 → 3.0.0-beta.3

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
@@ -1,5 +1,6 @@
1
1
  import { TranslationBundle } from '@jupyterlab/translation';
2
2
  import { Contents, Drive, User } from '@jupyterlab/services';
3
+ import { ISignal } from '@lumino/signaling';
3
4
  import { ICollaborativeDrive, ISharedModelFactory } from './tokens';
4
5
  import { Awareness } from 'y-protocols/awareness';
5
6
  /**
@@ -44,9 +45,14 @@ export declare class YDrive extends Drive implements ICollaborativeDrive {
44
45
  * file is saved.
45
46
  */
46
47
  save(localPath: string, options?: Partial<Contents.IModel>): Promise<Contents.IModel>;
48
+ /**
49
+ * A signal emitted when a file operation takes place.
50
+ */
51
+ get fileChanged(): ISignal<this, Contents.IChangedArgs>;
47
52
  private _onCreate;
48
53
  private _user;
49
54
  private _trans;
50
55
  private _providers;
51
56
  private _globalAwareness;
57
+ private _ydriveFileChanged;
52
58
  }
package/lib/ydrive.js CHANGED
@@ -2,6 +2,7 @@
2
2
  // Distributed under the terms of the Modified BSD License.
3
3
  import { PageConfig, URLExt } from '@jupyterlab/coreutils';
4
4
  import { Drive } from '@jupyterlab/services';
5
+ import { Signal } from '@lumino/signaling';
5
6
  import { WebSocketProvider } from './yprovider';
6
7
  const DISABLE_RTC = PageConfig.getOption('disableRTC') === 'true' ? true : false;
7
8
  /**
@@ -44,6 +45,30 @@ export class YDrive extends Drive {
44
45
  }
45
46
  const key = `${options.format}:${options.contentType}:${options.path}`;
46
47
  this._providers.set(key, provider);
48
+ sharedModel.changed.connect(async (_, change) => {
49
+ if (!change.stateChange) {
50
+ return;
51
+ }
52
+ const hashChanges = change.stateChange.filter(change => change.name === 'hash');
53
+ if (hashChanges.length === 0) {
54
+ return;
55
+ }
56
+ if (hashChanges.length > 1) {
57
+ console.error('Unexpected multiple changes to hash value in a single transaction');
58
+ }
59
+ const hashChange = hashChanges[0];
60
+ // A change in hash signifies that a save occurred on the server-side
61
+ // (e.g. a collaborator performed the save) - we want to notify the
62
+ // observers about this change so that they can store the new hash value.
63
+ const model = await this.get(options.path, { content: false });
64
+ this._ydriveFileChanged.emit({
65
+ type: 'save',
66
+ newValue: { ...model, hash: hashChange.newValue },
67
+ // we do not have the old model because it was discarded when server made the change,
68
+ // we only have the old hash here (which may be empty if the file was newly created!)
69
+ oldValue: { hash: hashChange.oldValue }
70
+ });
71
+ });
47
72
  sharedModel.disposed.connect(() => {
48
73
  var _a, _b;
49
74
  const provider = this._providers.get(key);
@@ -67,11 +92,16 @@ export class YDrive extends Drive {
67
92
  console.error(`Failed to open websocket connection for ${options.path}.\n:${error}`);
68
93
  }
69
94
  };
95
+ this._ydriveFileChanged = new Signal(this);
70
96
  this._user = user;
71
97
  this._trans = translator;
72
98
  this._globalAwareness = globalAwareness;
73
99
  this._providers = new Map();
74
100
  this.sharedModelFactory = new SharedModelFactory(this._onCreate);
101
+ super.fileChanged.connect((_, change) => {
102
+ // pass through any events from the Drive superclass
103
+ this._ydriveFileChanged.emit(change);
104
+ });
75
105
  }
76
106
  /**
77
107
  * Dispose of the resources held by the manager.
@@ -100,7 +130,7 @@ export class YDrive extends Drive {
100
130
  const key = `${options.format}:${options.type}:${localPath}`;
101
131
  const provider = this._providers.get(key);
102
132
  if (provider) {
103
- // If the document does't exist, `super.get` will reject with an
133
+ // If the document doesn't exist, `super.get` will reject with an
104
134
  // error and the provider will never be resolved.
105
135
  // Use `Promise.all` to reject as soon as possible. The Context will
106
136
  // show a dialog to the user.
@@ -140,6 +170,12 @@ export class YDrive extends Drive {
140
170
  }
141
171
  return super.save(localPath, options);
142
172
  }
173
+ /**
174
+ * A signal emitted when a file operation takes place.
175
+ */
176
+ get fileChanged() {
177
+ return this._ydriveFileChanged;
178
+ }
143
179
  }
144
180
  /**
145
181
  * Yjs sharedModel factory for real-time collaboration.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jupyter/docprovider",
3
- "version": "3.0.0-beta.1",
3
+ "version": "3.0.0-beta.3",
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/ydoc": "^2.0.0",
44
+ "@jupyter/ydoc": "^2.0.0 || ^3.0.0-a3",
45
45
  "@jupyterlab/apputils": "^4.2.0",
46
46
  "@jupyterlab/cells": "^4.2.0",
47
47
  "@jupyterlab/coreutils": "^6.2.0",