@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.
@@ -2452,7 +2452,7 @@ class HocuspocusProvider extends EventEmitter {
2452
2452
  };
2453
2453
  this.isConnected = true;
2454
2454
  this.boundBroadcastChannelSubscriber = this.broadcastChannelSubscriber.bind(this);
2455
- this.boundPageUnload = this.pageUnload.bind(this);
2455
+ this.boundPageHide = this.pageHide.bind(this);
2456
2456
  this.boundOnOpen = this.onOpen.bind(this);
2457
2457
  this.boundOnClose = this.onClose.bind(this);
2458
2458
  this.boundOnStatus = this.onStatus.bind(this);
@@ -2526,6 +2526,10 @@ class HocuspocusProvider extends EventEmitter {
2526
2526
  get hasUnsyncedChanges() {
2527
2527
  return this.unsyncedChanges > 0;
2528
2528
  }
2529
+ resetUnsyncedChanges() {
2530
+ this.unsyncedChanges = 1;
2531
+ this.emit('unsyncedChanges', this.unsyncedChanges);
2532
+ }
2529
2533
  incrementUnsyncedChanges() {
2530
2534
  this.unsyncedChanges += 1;
2531
2535
  this.emit('unsyncedChanges', this.unsyncedChanges);
@@ -2538,18 +2542,19 @@ class HocuspocusProvider extends EventEmitter {
2538
2542
  this.emit('unsyncedChanges', this.unsyncedChanges);
2539
2543
  }
2540
2544
  forceSync() {
2545
+ this.resetUnsyncedChanges();
2541
2546
  this.send(SyncStepOneMessage, { document: this.document, documentName: this.configuration.name });
2542
2547
  }
2543
- pageUnload() {
2548
+ pageHide() {
2544
2549
  if (this.awareness) {
2545
- removeAwarenessStates(this.awareness, [this.document.clientID], 'window unload');
2550
+ removeAwarenessStates(this.awareness, [this.document.clientID], 'page hide');
2546
2551
  }
2547
2552
  }
2548
2553
  registerEventListeners() {
2549
2554
  if (typeof window === 'undefined' || !('addEventListener' in window)) {
2550
2555
  return;
2551
2556
  }
2552
- window.addEventListener('unload', this.boundPageUnload);
2557
+ window.addEventListener('pagehide', this.boundPageHide);
2553
2558
  }
2554
2559
  sendStateless(payload) {
2555
2560
  this.send(StatelessMessage, { documentName: this.configuration.name, payload });
@@ -2592,7 +2597,7 @@ class HocuspocusProvider extends EventEmitter {
2592
2597
  get isAuthenticationRequired() {
2593
2598
  return !!this.configuration.token && !this.isAuthenticated;
2594
2599
  }
2595
- // not needed, but provides backward compatibility with e.g. lexicla/yjs
2600
+ // not needed, but provides backward compatibility with e.g. lexical/yjs
2596
2601
  async connect() {
2597
2602
  if (this.configuration.broadcast) {
2598
2603
  this.subscribeToBroadcastChannel();
@@ -2636,7 +2641,7 @@ class HocuspocusProvider extends EventEmitter {
2636
2641
  return this.configuration.token;
2637
2642
  }
2638
2643
  startSync() {
2639
- this.incrementUnsyncedChanges();
2644
+ this.resetUnsyncedChanges();
2640
2645
  this.send(SyncStepOneMessage, { document: this.document, documentName: this.configuration.name });
2641
2646
  if (this.awareness && this.awareness.getLocalState() !== null) {
2642
2647
  this.send(AwarenessMessage, {
@@ -2701,7 +2706,7 @@ class HocuspocusProvider extends EventEmitter {
2701
2706
  if (typeof window === 'undefined' || !('removeEventListener' in window)) {
2702
2707
  return;
2703
2708
  }
2704
- window.removeEventListener('unload', this.boundPageUnload);
2709
+ window.removeEventListener('pagehide', this.boundPageHide);
2705
2710
  }
2706
2711
  permissionDeniedHandler(reason) {
2707
2712
  this.emit('authenticationFailed', { reason });