@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
|
@@ -1705,6 +1705,7 @@ var MessageType;
|
|
|
1705
1705
|
MessageType[MessageType["QueryAwareness"] = 3] = "QueryAwareness";
|
|
1706
1706
|
MessageType[MessageType["Stateless"] = 5] = "Stateless";
|
|
1707
1707
|
MessageType[MessageType["CLOSE"] = 7] = "CLOSE";
|
|
1708
|
+
MessageType[MessageType["SyncStatus"] = 8] = "SyncStatus";
|
|
1708
1709
|
})(MessageType || (MessageType = {}));
|
|
1709
1710
|
var WebSocketStatus;
|
|
1710
1711
|
(function (WebSocketStatus) {
|
|
@@ -1754,6 +1755,9 @@ class MessageReceiver {
|
|
|
1754
1755
|
case MessageType.Stateless:
|
|
1755
1756
|
provider.receiveStateless(readVarString(message.decoder));
|
|
1756
1757
|
break;
|
|
1758
|
+
case MessageType.SyncStatus:
|
|
1759
|
+
// nothing for now; forward-compatability
|
|
1760
|
+
break;
|
|
1757
1761
|
default:
|
|
1758
1762
|
throw new Error(`Can’t apply message of unknown type: ${type}`);
|
|
1759
1763
|
}
|
|
@@ -2319,8 +2323,17 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2319
2323
|
forceSync: null,
|
|
2320
2324
|
};
|
|
2321
2325
|
this.isConnected = true;
|
|
2322
|
-
this.boundBeforeUnload = this.beforeUnload.bind(this);
|
|
2323
2326
|
this.boundBroadcastChannelSubscriber = this.broadcastChannelSubscriber.bind(this);
|
|
2327
|
+
this.boundBeforeUnload = this.beforeUnload.bind(this);
|
|
2328
|
+
this.boundOnOpen = this.onOpen.bind(this);
|
|
2329
|
+
this.boundOnMessage = this.onMessage.bind(this);
|
|
2330
|
+
this.boundOnClose = this.onClose.bind(this);
|
|
2331
|
+
this.boundOnStatus = this.onStatus.bind(this);
|
|
2332
|
+
this.forwardConnect = (e) => this.emit('connect', e);
|
|
2333
|
+
this.forwardOpen = (e) => this.emit('open', e);
|
|
2334
|
+
this.forwardClose = (e) => this.emit('close', e);
|
|
2335
|
+
this.forwardDisconnect = (e) => this.emit('disconnect', e);
|
|
2336
|
+
this.forwardDestroy = (e) => this.emit('destroy', e);
|
|
2324
2337
|
this.setConfiguration(configuration);
|
|
2325
2338
|
this.configuration.document = configuration.document ? configuration.document : new Y.Doc();
|
|
2326
2339
|
this.configuration.awareness = configuration.awareness ? configuration.awareness : new Awareness(this.document);
|
|
@@ -2335,18 +2348,18 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2335
2348
|
this.on('authenticated', this.configuration.onAuthenticated);
|
|
2336
2349
|
this.on('authenticationFailed', this.configuration.onAuthenticationFailed);
|
|
2337
2350
|
this.configuration.websocketProvider.on('connect', this.configuration.onConnect);
|
|
2338
|
-
this.configuration.websocketProvider.on('connect',
|
|
2339
|
-
this.configuration.websocketProvider.on('open', this.
|
|
2340
|
-
this.configuration.websocketProvider.on('open',
|
|
2341
|
-
this.configuration.websocketProvider.on('message', this.
|
|
2342
|
-
this.configuration.websocketProvider.on('close', this.
|
|
2351
|
+
this.configuration.websocketProvider.on('connect', this.forwardConnect);
|
|
2352
|
+
this.configuration.websocketProvider.on('open', this.boundOnOpen);
|
|
2353
|
+
this.configuration.websocketProvider.on('open', this.forwardOpen);
|
|
2354
|
+
this.configuration.websocketProvider.on('message', this.boundOnMessage);
|
|
2355
|
+
this.configuration.websocketProvider.on('close', this.boundOnClose);
|
|
2343
2356
|
this.configuration.websocketProvider.on('close', this.configuration.onClose);
|
|
2344
|
-
this.configuration.websocketProvider.on('close',
|
|
2345
|
-
this.configuration.websocketProvider.on('status', this.
|
|
2357
|
+
this.configuration.websocketProvider.on('close', this.forwardClose);
|
|
2358
|
+
this.configuration.websocketProvider.on('status', this.boundOnStatus);
|
|
2346
2359
|
this.configuration.websocketProvider.on('disconnect', this.configuration.onDisconnect);
|
|
2347
|
-
this.configuration.websocketProvider.on('disconnect',
|
|
2360
|
+
this.configuration.websocketProvider.on('disconnect', this.forwardDisconnect);
|
|
2348
2361
|
this.configuration.websocketProvider.on('destroy', this.configuration.onDestroy);
|
|
2349
|
-
this.configuration.websocketProvider.on('destroy',
|
|
2362
|
+
this.configuration.websocketProvider.on('destroy', this.forwardDestroy);
|
|
2350
2363
|
this.awareness.on('update', () => {
|
|
2351
2364
|
this.emit('awarenessUpdate', { states: awarenessStatesToArray(this.awareness.getStates()) });
|
|
2352
2365
|
});
|
|
@@ -2511,6 +2524,19 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2511
2524
|
this.awareness.off('update', this.awarenessUpdateHandler);
|
|
2512
2525
|
this.document.off('update', this.documentUpdateHandler);
|
|
2513
2526
|
this.removeAllListeners();
|
|
2527
|
+
this.configuration.websocketProvider.off('connect', this.configuration.onConnect);
|
|
2528
|
+
this.configuration.websocketProvider.off('connect', this.forwardConnect);
|
|
2529
|
+
this.configuration.websocketProvider.off('open', this.boundOnOpen);
|
|
2530
|
+
this.configuration.websocketProvider.off('open', this.forwardOpen);
|
|
2531
|
+
this.configuration.websocketProvider.off('message', this.boundOnMessage);
|
|
2532
|
+
this.configuration.websocketProvider.off('close', this.boundOnClose);
|
|
2533
|
+
this.configuration.websocketProvider.off('close', this.configuration.onClose);
|
|
2534
|
+
this.configuration.websocketProvider.off('close', this.forwardClose);
|
|
2535
|
+
this.configuration.websocketProvider.off('status', this.boundOnStatus);
|
|
2536
|
+
this.configuration.websocketProvider.off('disconnect', this.configuration.onDisconnect);
|
|
2537
|
+
this.configuration.websocketProvider.off('disconnect', this.forwardDisconnect);
|
|
2538
|
+
this.configuration.websocketProvider.off('destroy', this.configuration.onDestroy);
|
|
2539
|
+
this.configuration.websocketProvider.off('destroy', this.forwardDestroy);
|
|
2514
2540
|
this.send(CloseMessage, { documentName: this.configuration.name });
|
|
2515
2541
|
this.isConnected = false;
|
|
2516
2542
|
if (typeof window === 'undefined') {
|
|
@@ -2597,6 +2623,39 @@ class TiptapCollabProvider extends HocuspocusProvider {
|
|
|
2597
2623
|
configuration.token = 'notoken'; // need to send a token anyway (which will be ignored)
|
|
2598
2624
|
}
|
|
2599
2625
|
super(configuration);
|
|
2626
|
+
this.tiptapCollabConfigurationPrefix = '__tiptapcollab__';
|
|
2627
|
+
}
|
|
2628
|
+
createVersion(name) {
|
|
2629
|
+
console.error('This doesnt work yet! If you want to join as a beta tester, send an email to humans@tiptap.dev');
|
|
2630
|
+
return this.sendStateless(JSON.stringify({ action: 'version.create', name }));
|
|
2631
|
+
}
|
|
2632
|
+
revertToVersion(targetVersion) {
|
|
2633
|
+
console.error('This doesnt work yet! If you want to join as a beta tester, send an email to humans@tiptap.dev');
|
|
2634
|
+
return this.sendStateless(JSON.stringify({ action: 'version.revert', version: targetVersion }));
|
|
2635
|
+
}
|
|
2636
|
+
getVersions() {
|
|
2637
|
+
console.error('This doesnt work yet! If you want to join as a beta tester, send an email to humans@tiptap.dev');
|
|
2638
|
+
return this.configuration.document.getArray(`${this.tiptapCollabConfigurationPrefix}versions`).toArray();
|
|
2639
|
+
}
|
|
2640
|
+
watchVersions(callback) {
|
|
2641
|
+
console.error('This doesnt work yet! If you want to join as a beta tester, send an email to humans@tiptap.dev');
|
|
2642
|
+
return this.configuration.document.getArray('__tiptapcollab__versions').observe(callback);
|
|
2643
|
+
}
|
|
2644
|
+
unwatchVersions(callback) {
|
|
2645
|
+
console.error('This doesnt work yet! If you want to join as a beta tester, send an email to humans@tiptap.dev');
|
|
2646
|
+
return this.configuration.document.getArray('__tiptapcollab__versions').unobserve(callback);
|
|
2647
|
+
}
|
|
2648
|
+
isAutoVersioning() {
|
|
2649
|
+
console.error('This doesnt work yet! If you want to join as a beta tester, send an email to humans@tiptap.dev');
|
|
2650
|
+
return !!this.configuration.document.getMap(`${this.tiptapCollabConfigurationPrefix}config`).get('autoVersioning');
|
|
2651
|
+
}
|
|
2652
|
+
enableAutoVersioning() {
|
|
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.configuration.document.getMap(`${this.tiptapCollabConfigurationPrefix}config`).set('autoVersioning', 1);
|
|
2655
|
+
}
|
|
2656
|
+
disableAutoVersioning() {
|
|
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.configuration.document.getMap(`${this.tiptapCollabConfigurationPrefix}config`).set('autoVersioning', 0);
|
|
2600
2659
|
}
|
|
2601
2660
|
}
|
|
2602
2661
|
|