@jupyter/docprovider 5.0.0 → 5.0.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.
Files changed (2) hide show
  1. package/lib/ydrive.js +23 -7
  2. package/package.json +2 -2
package/lib/ydrive.js CHANGED
@@ -73,19 +73,24 @@ export class RtcContentProvider {
73
73
  if (!oldPath || !newPath) {
74
74
  // This is expected when shared model initializes and the path is first populated
75
75
  console.debug('New or old path not given', pathChange);
76
- return;
76
+ return false;
77
+ }
78
+ // A rename can be reported by both the drive and the shared model.
79
+ // Do not process the second notification again.
80
+ if (oldPath !== path && newPath === path) {
81
+ return false;
77
82
  }
78
83
  const oldKey = `${options.format}:${options.contentType}:${oldPath}`;
79
84
  if (oldKey !== key) {
80
85
  console.error('The computed old provider key is different from the current key');
81
- return;
86
+ return false;
82
87
  }
83
88
  const newKey = `${options.format}:${options.contentType}:${newPath}`;
84
89
  // Check if the provider is still registered (it may have been disposed if document was closed)
85
90
  const provider = this._providers.get(oldKey);
86
91
  if (!provider) {
87
92
  console.warn(`Could not find a provider to update after rename ${oldKey}, ${newKey}`);
88
- return;
93
+ return false;
89
94
  }
90
95
  // Re-register the provider under the new key
91
96
  this._providers.set(newKey, provider);
@@ -102,6 +107,7 @@ export class RtcContentProvider {
102
107
  documents.push(newPath);
103
108
  (_b = this._globalAwareness) === null || _b === void 0 ? void 0 : _b.setLocalStateField('documents', documents);
104
109
  }
110
+ return true;
105
111
  };
106
112
  // The information about file being renamed can come from two places:
107
113
  // - from the sharedModel via changed signal with documentChange
@@ -129,13 +135,21 @@ export class RtcContentProvider {
129
135
  };
130
136
  (_c = this._driveFileChanged) === null || _c === void 0 ? void 0 : _c.connect(handleFileChangedSignal);
131
137
  sharedModel.changed.connect(async (_, change) => {
132
- var _a;
133
138
  if (!change.stateChange) {
134
139
  return;
135
140
  }
136
141
  const pathChanges = change.stateChange.filter(change => change.name === 'path');
137
142
  for (const pathChange of pathChanges) {
138
- handlePathChange(pathChange);
143
+ if (handlePathChange(pathChange)) {
144
+ // The drive emits a rename directly in the client that initiated
145
+ // it. Other clients learn about it through the shared model, so
146
+ // proxy that change to their ContentsManager/DocumentContext too.
147
+ this._providerFileChanged.emit({
148
+ type: 'rename',
149
+ oldValue: { path: pathChange.oldValue },
150
+ newValue: { path: pathChange.newValue }
151
+ });
152
+ }
139
153
  }
140
154
  const hashChanges = change.stateChange.filter(change => change.name === 'hash');
141
155
  if (hashChanges.length === 0) {
@@ -148,8 +162,10 @@ export class RtcContentProvider {
148
162
  // A change in hash signifies that a save occurred on the server-side
149
163
  // (e.g. a collaborator performed the save) - we want to notify the
150
164
  // observers about this change so that they can store the new hash value.
151
- const newPath = (_a = sharedModel.state.path) !== null && _a !== void 0 ? _a : options.path;
152
- const model = await this.get(newPath, { content: false });
165
+ // Use the path tracked by the provider. During a rename transaction,
166
+ // the state accessor may still expose the old path even though the
167
+ // path state change above has already been processed.
168
+ const model = await this.get(path, { content: false });
153
169
  this._providerFileChanged.emit({
154
170
  type: 'save',
155
171
  newValue: { ...model, hash: hashChange.newValue },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jupyter/docprovider",
3
- "version": "5.0.0",
3
+ "version": "5.0.1",
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": "^5.0.0",
44
+ "@jupyter/collaborative-drive": "^5.0.1",
45
45
  "@jupyter/ydoc": "^4.0.0",
46
46
  "@jupyterlab/apputils": "^4.7.0",
47
47
  "@jupyterlab/cells": "^4.6.0",