@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.
@@ -89,7 +89,7 @@ export declare class HocuspocusProvider extends EventEmitter {
89
89
  isConnected: boolean;
90
90
  constructor(configuration: HocuspocusProviderConfiguration);
91
91
  boundBroadcastChannelSubscriber: (data: ArrayBuffer) => void;
92
- boundPageUnload: () => void;
92
+ boundPageHide: () => void;
93
93
  boundOnOpen: (event: Event) => Promise<void>;
94
94
  boundOnClose: (event: CloseEvent) => void;
95
95
  boundOnStatus: ({ status }: onStatusParameters) => void;
@@ -103,10 +103,11 @@ export declare class HocuspocusProvider extends EventEmitter {
103
103
  get document(): Y.Doc;
104
104
  get awareness(): Awareness | null;
105
105
  get hasUnsyncedChanges(): boolean;
106
+ private resetUnsyncedChanges;
106
107
  incrementUnsyncedChanges(): void;
107
108
  decrementUnsyncedChanges(): void;
108
109
  forceSync(): void;
109
- pageUnload(): void;
110
+ pageHide(): void;
110
111
  registerEventListeners(): void;
111
112
  sendStateless(payload: string): void;
112
113
  documentUpdateHandler(update: Uint8Array, origin: any): void;
@@ -89,7 +89,7 @@ export declare class Hocuspocus {
89
89
  */
90
90
  createDocument(documentName: string, request: Partial<Pick<IncomingMessage, 'headers' | 'url'>>, socketId: string, connection: ConnectionConfiguration, context?: any): Promise<Document>;
91
91
  loadDocument(documentName: string, request: Partial<Pick<IncomingMessage, 'headers' | 'url'>>, socketId: string, connection: ConnectionConfiguration, context?: any): Promise<Document>;
92
- storeDocumentHooks(document: Document, hookPayload: onStoreDocumentPayload): Promise<void>;
92
+ storeDocumentHooks(document: Document, hookPayload: onStoreDocumentPayload, immediately?: boolean): any;
93
93
  /**
94
94
  * Run the given hook on all configured extensions.
95
95
  * Runs the given callback after each hook.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hocuspocus/provider",
3
- "version": "2.13.0",
3
+ "version": "2.13.2",
4
4
  "description": "hocuspocus provider",
5
5
  "homepage": "https://hocuspocus.dev",
6
6
  "keywords": [
@@ -29,7 +29,7 @@
29
29
  "dist"
30
30
  ],
31
31
  "dependencies": {
32
- "@hocuspocus/common": "^2.13.0",
32
+ "@hocuspocus/common": "^2.13.2",
33
33
  "@lifeomic/attempt": "^3.0.2",
34
34
  "lib0": "^0.2.87",
35
35
  "ws": "^8.14.2"
@@ -231,7 +231,7 @@ export class HocuspocusProvider extends EventEmitter {
231
231
 
232
232
  boundBroadcastChannelSubscriber = this.broadcastChannelSubscriber.bind(this)
233
233
 
234
- boundPageUnload = this.pageUnload.bind(this)
234
+ boundPageHide = this.pageHide.bind(this)
235
235
 
236
236
  boundOnOpen = this.onOpen.bind(this)
237
237
 
@@ -282,6 +282,11 @@ export class HocuspocusProvider extends EventEmitter {
282
282
  return this.unsyncedChanges > 0
283
283
  }
284
284
 
285
+ private resetUnsyncedChanges() {
286
+ this.unsyncedChanges = 1
287
+ this.emit('unsyncedChanges', this.unsyncedChanges)
288
+ }
289
+
285
290
  incrementUnsyncedChanges() {
286
291
  this.unsyncedChanges += 1
287
292
  this.emit('unsyncedChanges', this.unsyncedChanges)
@@ -296,12 +301,14 @@ export class HocuspocusProvider extends EventEmitter {
296
301
  }
297
302
 
298
303
  forceSync() {
304
+ this.resetUnsyncedChanges()
305
+
299
306
  this.send(SyncStepOneMessage, { document: this.document, documentName: this.configuration.name })
300
307
  }
301
308
 
302
- pageUnload() {
309
+ pageHide() {
303
310
  if (this.awareness) {
304
- removeAwarenessStates(this.awareness, [this.document.clientID], 'window unload')
311
+ removeAwarenessStates(this.awareness, [this.document.clientID], 'page hide')
305
312
  }
306
313
  }
307
314
 
@@ -310,7 +317,7 @@ export class HocuspocusProvider extends EventEmitter {
310
317
  return
311
318
  }
312
319
 
313
- window.addEventListener('unload', this.boundPageUnload)
320
+ window.addEventListener('pagehide', this.boundPageHide)
314
321
  }
315
322
 
316
323
  sendStateless(payload: string) {
@@ -364,7 +371,7 @@ export class HocuspocusProvider extends EventEmitter {
364
371
  return !!this.configuration.token && !this.isAuthenticated
365
372
  }
366
373
 
367
- // not needed, but provides backward compatibility with e.g. lexicla/yjs
374
+ // not needed, but provides backward compatibility with e.g. lexical/yjs
368
375
  async connect() {
369
376
  if (this.configuration.broadcast) {
370
377
  this.subscribeToBroadcastChannel()
@@ -420,7 +427,8 @@ export class HocuspocusProvider extends EventEmitter {
420
427
  }
421
428
 
422
429
  startSync() {
423
- this.incrementUnsyncedChanges()
430
+ this.resetUnsyncedChanges()
431
+
424
432
  this.send(SyncStepOneMessage, { document: this.document, documentName: this.configuration.name })
425
433
 
426
434
  if (this.awareness && this.awareness.getLocalState() !== null) {
@@ -510,7 +518,7 @@ export class HocuspocusProvider extends EventEmitter {
510
518
  return
511
519
  }
512
520
 
513
- window.removeEventListener('unload', this.boundPageUnload)
521
+ window.removeEventListener('pagehide', this.boundPageHide)
514
522
  }
515
523
 
516
524
  permissionDeniedHandler(reason: string) {