@hocuspocus/provider 2.2.1 → 2.2.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/dist/hocuspocus-provider.cjs +69 -10
- package/dist/hocuspocus-provider.cjs.map +1 -1
- package/dist/hocuspocus-provider.esm.js +69 -10
- package/dist/hocuspocus-provider.esm.js.map +1 -1
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +11 -2
- package/dist/packages/provider/src/TiptapCollabProvider.d.ts +19 -2
- package/dist/packages/provider/src/types.d.ts +6 -5
- package/dist/packages/server/src/DirectConnection.d.ts +1 -1
- package/package.json +2 -2
- package/src/HocuspocusProvider.ts +45 -13
- package/src/MessageReceiver.ts +4 -0
- package/src/TiptapCollabProvider.ts +56 -3
- package/src/types.ts +5 -4
|
@@ -1729,6 +1729,7 @@ exports.MessageType = void 0;
|
|
|
1729
1729
|
MessageType[MessageType["QueryAwareness"] = 3] = "QueryAwareness";
|
|
1730
1730
|
MessageType[MessageType["Stateless"] = 5] = "Stateless";
|
|
1731
1731
|
MessageType[MessageType["CLOSE"] = 7] = "CLOSE";
|
|
1732
|
+
MessageType[MessageType["SyncStatus"] = 8] = "SyncStatus";
|
|
1732
1733
|
})(exports.MessageType || (exports.MessageType = {}));
|
|
1733
1734
|
exports.WebSocketStatus = void 0;
|
|
1734
1735
|
(function (WebSocketStatus) {
|
|
@@ -1778,6 +1779,9 @@ class MessageReceiver {
|
|
|
1778
1779
|
case exports.MessageType.Stateless:
|
|
1779
1780
|
provider.receiveStateless(readVarString(message.decoder));
|
|
1780
1781
|
break;
|
|
1782
|
+
case exports.MessageType.SyncStatus:
|
|
1783
|
+
// nothing for now; forward-compatability
|
|
1784
|
+
break;
|
|
1781
1785
|
default:
|
|
1782
1786
|
throw new Error(`Can’t apply message of unknown type: ${type}`);
|
|
1783
1787
|
}
|
|
@@ -2343,8 +2347,17 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2343
2347
|
forceSync: null,
|
|
2344
2348
|
};
|
|
2345
2349
|
this.isConnected = true;
|
|
2346
|
-
this.boundBeforeUnload = this.beforeUnload.bind(this);
|
|
2347
2350
|
this.boundBroadcastChannelSubscriber = this.broadcastChannelSubscriber.bind(this);
|
|
2351
|
+
this.boundBeforeUnload = this.beforeUnload.bind(this);
|
|
2352
|
+
this.boundOnOpen = this.onOpen.bind(this);
|
|
2353
|
+
this.boundOnMessage = this.onMessage.bind(this);
|
|
2354
|
+
this.boundOnClose = this.onClose.bind(this);
|
|
2355
|
+
this.boundOnStatus = this.onStatus.bind(this);
|
|
2356
|
+
this.forwardConnect = (e) => this.emit('connect', e);
|
|
2357
|
+
this.forwardOpen = (e) => this.emit('open', e);
|
|
2358
|
+
this.forwardClose = (e) => this.emit('close', e);
|
|
2359
|
+
this.forwardDisconnect = (e) => this.emit('disconnect', e);
|
|
2360
|
+
this.forwardDestroy = (e) => this.emit('destroy', e);
|
|
2348
2361
|
this.setConfiguration(configuration);
|
|
2349
2362
|
this.configuration.document = configuration.document ? configuration.document : new Y__namespace.Doc();
|
|
2350
2363
|
this.configuration.awareness = configuration.awareness ? configuration.awareness : new Awareness(this.document);
|
|
@@ -2359,18 +2372,18 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2359
2372
|
this.on('authenticated', this.configuration.onAuthenticated);
|
|
2360
2373
|
this.on('authenticationFailed', this.configuration.onAuthenticationFailed);
|
|
2361
2374
|
this.configuration.websocketProvider.on('connect', this.configuration.onConnect);
|
|
2362
|
-
this.configuration.websocketProvider.on('connect',
|
|
2363
|
-
this.configuration.websocketProvider.on('open', this.
|
|
2364
|
-
this.configuration.websocketProvider.on('open',
|
|
2365
|
-
this.configuration.websocketProvider.on('message', this.
|
|
2366
|
-
this.configuration.websocketProvider.on('close', this.
|
|
2375
|
+
this.configuration.websocketProvider.on('connect', this.forwardConnect);
|
|
2376
|
+
this.configuration.websocketProvider.on('open', this.boundOnOpen);
|
|
2377
|
+
this.configuration.websocketProvider.on('open', this.forwardOpen);
|
|
2378
|
+
this.configuration.websocketProvider.on('message', this.boundOnMessage);
|
|
2379
|
+
this.configuration.websocketProvider.on('close', this.boundOnClose);
|
|
2367
2380
|
this.configuration.websocketProvider.on('close', this.configuration.onClose);
|
|
2368
|
-
this.configuration.websocketProvider.on('close',
|
|
2369
|
-
this.configuration.websocketProvider.on('status', this.
|
|
2381
|
+
this.configuration.websocketProvider.on('close', this.forwardClose);
|
|
2382
|
+
this.configuration.websocketProvider.on('status', this.boundOnStatus);
|
|
2370
2383
|
this.configuration.websocketProvider.on('disconnect', this.configuration.onDisconnect);
|
|
2371
|
-
this.configuration.websocketProvider.on('disconnect',
|
|
2384
|
+
this.configuration.websocketProvider.on('disconnect', this.forwardDisconnect);
|
|
2372
2385
|
this.configuration.websocketProvider.on('destroy', this.configuration.onDestroy);
|
|
2373
|
-
this.configuration.websocketProvider.on('destroy',
|
|
2386
|
+
this.configuration.websocketProvider.on('destroy', this.forwardDestroy);
|
|
2374
2387
|
this.awareness.on('update', () => {
|
|
2375
2388
|
this.emit('awarenessUpdate', { states: common.awarenessStatesToArray(this.awareness.getStates()) });
|
|
2376
2389
|
});
|
|
@@ -2535,6 +2548,19 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2535
2548
|
this.awareness.off('update', this.awarenessUpdateHandler);
|
|
2536
2549
|
this.document.off('update', this.documentUpdateHandler);
|
|
2537
2550
|
this.removeAllListeners();
|
|
2551
|
+
this.configuration.websocketProvider.off('connect', this.configuration.onConnect);
|
|
2552
|
+
this.configuration.websocketProvider.off('connect', this.forwardConnect);
|
|
2553
|
+
this.configuration.websocketProvider.off('open', this.boundOnOpen);
|
|
2554
|
+
this.configuration.websocketProvider.off('open', this.forwardOpen);
|
|
2555
|
+
this.configuration.websocketProvider.off('message', this.boundOnMessage);
|
|
2556
|
+
this.configuration.websocketProvider.off('close', this.boundOnClose);
|
|
2557
|
+
this.configuration.websocketProvider.off('close', this.configuration.onClose);
|
|
2558
|
+
this.configuration.websocketProvider.off('close', this.forwardClose);
|
|
2559
|
+
this.configuration.websocketProvider.off('status', this.boundOnStatus);
|
|
2560
|
+
this.configuration.websocketProvider.off('disconnect', this.configuration.onDisconnect);
|
|
2561
|
+
this.configuration.websocketProvider.off('disconnect', this.forwardDisconnect);
|
|
2562
|
+
this.configuration.websocketProvider.off('destroy', this.configuration.onDestroy);
|
|
2563
|
+
this.configuration.websocketProvider.off('destroy', this.forwardDestroy);
|
|
2538
2564
|
this.send(CloseMessage, { documentName: this.configuration.name });
|
|
2539
2565
|
this.isConnected = false;
|
|
2540
2566
|
if (typeof window === 'undefined') {
|
|
@@ -2621,6 +2647,39 @@ class TiptapCollabProvider extends HocuspocusProvider {
|
|
|
2621
2647
|
configuration.token = 'notoken'; // need to send a token anyway (which will be ignored)
|
|
2622
2648
|
}
|
|
2623
2649
|
super(configuration);
|
|
2650
|
+
this.tiptapCollabConfigurationPrefix = '__tiptapcollab__';
|
|
2651
|
+
}
|
|
2652
|
+
createVersion(name) {
|
|
2653
|
+
console.error('This doesnt work yet! If you want to join as a beta tester, send an email to humans@tiptap.dev');
|
|
2654
|
+
return this.sendStateless(JSON.stringify({ action: 'version.create', name }));
|
|
2655
|
+
}
|
|
2656
|
+
revertToVersion(targetVersion) {
|
|
2657
|
+
console.error('This doesnt work yet! If you want to join as a beta tester, send an email to humans@tiptap.dev');
|
|
2658
|
+
return this.sendStateless(JSON.stringify({ action: 'version.revert', version: targetVersion }));
|
|
2659
|
+
}
|
|
2660
|
+
getVersions() {
|
|
2661
|
+
console.error('This doesnt work yet! If you want to join as a beta tester, send an email to humans@tiptap.dev');
|
|
2662
|
+
return this.configuration.document.getArray(`${this.tiptapCollabConfigurationPrefix}versions`).toArray();
|
|
2663
|
+
}
|
|
2664
|
+
watchVersions(callback) {
|
|
2665
|
+
console.error('This doesnt work yet! If you want to join as a beta tester, send an email to humans@tiptap.dev');
|
|
2666
|
+
return this.configuration.document.getArray('__tiptapcollab__versions').observe(callback);
|
|
2667
|
+
}
|
|
2668
|
+
unwatchVersions(callback) {
|
|
2669
|
+
console.error('This doesnt work yet! If you want to join as a beta tester, send an email to humans@tiptap.dev');
|
|
2670
|
+
return this.configuration.document.getArray('__tiptapcollab__versions').unobserve(callback);
|
|
2671
|
+
}
|
|
2672
|
+
isAutoVersioning() {
|
|
2673
|
+
console.error('This doesnt work yet! If you want to join as a beta tester, send an email to humans@tiptap.dev');
|
|
2674
|
+
return !!this.configuration.document.getMap(`${this.tiptapCollabConfigurationPrefix}config`).get('autoVersioning');
|
|
2675
|
+
}
|
|
2676
|
+
enableAutoVersioning() {
|
|
2677
|
+
console.error('This doesnt work yet! If you want to join as a beta tester, send an email to humans@tiptap.dev');
|
|
2678
|
+
return this.configuration.document.getMap(`${this.tiptapCollabConfigurationPrefix}config`).set('autoVersioning', 1);
|
|
2679
|
+
}
|
|
2680
|
+
disableAutoVersioning() {
|
|
2681
|
+
console.error('This doesnt work yet! If you want to join as a beta tester, send an email to humans@tiptap.dev');
|
|
2682
|
+
return this.configuration.document.getMap(`${this.tiptapCollabConfigurationPrefix}config`).set('autoVersioning', 0);
|
|
2624
2683
|
}
|
|
2625
2684
|
}
|
|
2626
2685
|
|