@hocuspocus/provider 2.13.0 → 2.13.2
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 +12 -7
- package/dist/hocuspocus-provider.cjs.map +1 -1
- package/dist/hocuspocus-provider.esm.js +12 -7
- package/dist/hocuspocus-provider.esm.js.map +1 -1
- package/dist/packages/provider/src/HocuspocusProvider.d.ts +3 -2
- package/dist/packages/server/src/Hocuspocus.d.ts +1 -1
- package/package.json +2 -2
- package/src/HocuspocusProvider.ts +15 -7
|
@@ -2476,7 +2476,7 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2476
2476
|
};
|
|
2477
2477
|
this.isConnected = true;
|
|
2478
2478
|
this.boundBroadcastChannelSubscriber = this.broadcastChannelSubscriber.bind(this);
|
|
2479
|
-
this.
|
|
2479
|
+
this.boundPageHide = this.pageHide.bind(this);
|
|
2480
2480
|
this.boundOnOpen = this.onOpen.bind(this);
|
|
2481
2481
|
this.boundOnClose = this.onClose.bind(this);
|
|
2482
2482
|
this.boundOnStatus = this.onStatus.bind(this);
|
|
@@ -2550,6 +2550,10 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2550
2550
|
get hasUnsyncedChanges() {
|
|
2551
2551
|
return this.unsyncedChanges > 0;
|
|
2552
2552
|
}
|
|
2553
|
+
resetUnsyncedChanges() {
|
|
2554
|
+
this.unsyncedChanges = 1;
|
|
2555
|
+
this.emit('unsyncedChanges', this.unsyncedChanges);
|
|
2556
|
+
}
|
|
2553
2557
|
incrementUnsyncedChanges() {
|
|
2554
2558
|
this.unsyncedChanges += 1;
|
|
2555
2559
|
this.emit('unsyncedChanges', this.unsyncedChanges);
|
|
@@ -2562,18 +2566,19 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2562
2566
|
this.emit('unsyncedChanges', this.unsyncedChanges);
|
|
2563
2567
|
}
|
|
2564
2568
|
forceSync() {
|
|
2569
|
+
this.resetUnsyncedChanges();
|
|
2565
2570
|
this.send(SyncStepOneMessage, { document: this.document, documentName: this.configuration.name });
|
|
2566
2571
|
}
|
|
2567
|
-
|
|
2572
|
+
pageHide() {
|
|
2568
2573
|
if (this.awareness) {
|
|
2569
|
-
removeAwarenessStates(this.awareness, [this.document.clientID], '
|
|
2574
|
+
removeAwarenessStates(this.awareness, [this.document.clientID], 'page hide');
|
|
2570
2575
|
}
|
|
2571
2576
|
}
|
|
2572
2577
|
registerEventListeners() {
|
|
2573
2578
|
if (typeof window === 'undefined' || !('addEventListener' in window)) {
|
|
2574
2579
|
return;
|
|
2575
2580
|
}
|
|
2576
|
-
window.addEventListener('
|
|
2581
|
+
window.addEventListener('pagehide', this.boundPageHide);
|
|
2577
2582
|
}
|
|
2578
2583
|
sendStateless(payload) {
|
|
2579
2584
|
this.send(StatelessMessage, { documentName: this.configuration.name, payload });
|
|
@@ -2616,7 +2621,7 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2616
2621
|
get isAuthenticationRequired() {
|
|
2617
2622
|
return !!this.configuration.token && !this.isAuthenticated;
|
|
2618
2623
|
}
|
|
2619
|
-
// not needed, but provides backward compatibility with e.g.
|
|
2624
|
+
// not needed, but provides backward compatibility with e.g. lexical/yjs
|
|
2620
2625
|
async connect() {
|
|
2621
2626
|
if (this.configuration.broadcast) {
|
|
2622
2627
|
this.subscribeToBroadcastChannel();
|
|
@@ -2660,7 +2665,7 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2660
2665
|
return this.configuration.token;
|
|
2661
2666
|
}
|
|
2662
2667
|
startSync() {
|
|
2663
|
-
this.
|
|
2668
|
+
this.resetUnsyncedChanges();
|
|
2664
2669
|
this.send(SyncStepOneMessage, { document: this.document, documentName: this.configuration.name });
|
|
2665
2670
|
if (this.awareness && this.awareness.getLocalState() !== null) {
|
|
2666
2671
|
this.send(AwarenessMessage, {
|
|
@@ -2725,7 +2730,7 @@ class HocuspocusProvider extends EventEmitter {
|
|
|
2725
2730
|
if (typeof window === 'undefined' || !('removeEventListener' in window)) {
|
|
2726
2731
|
return;
|
|
2727
2732
|
}
|
|
2728
|
-
window.removeEventListener('
|
|
2733
|
+
window.removeEventListener('pagehide', this.boundPageHide);
|
|
2729
2734
|
}
|
|
2730
2735
|
permissionDeniedHandler(reason) {
|
|
2731
2736
|
this.emit('authenticationFailed', { reason });
|