@@ -264,26 +264,36 @@ export class Hocuspocus<Context = any> {
264264 : { }
265265 : { } ;
266266
267- const hookPayload : onChangePayload | onStoreDocumentPayload = {
267+ const changePayload : onChangePayload = {
268268 instance : this ,
269269 clientsCount : document . getConnectionsCount ( ) ,
270- context,
271270 document,
272271 documentName : document . name ,
273272 requestHeaders : request ?. headers ?? { } ,
274273 requestParameters : getParameters ( request ) ,
275274 socketId : connection ?. socketId ?? "" ,
276275 update,
277276 transactionOrigin : origin ,
277+ connection : connection ,
278+ context,
278279 } ;
279280
280- this . hooks ( "onChange" , hookPayload ) ;
281+ this . hooks ( "onChange" , changePayload ) ;
281282
282283 if ( shouldSkipStoreHooks ( origin ) ) {
283284 return ;
284285 }
285286
286- this . storeDocumentHooks ( document , hookPayload ) ;
287+ const storePayload : onStoreDocumentPayload = {
288+ instance : this ,
289+ clientsCount : document . getConnectionsCount ( ) ,
290+ document,
291+ lastContext : context ,
292+ lastTransactionOrigin : origin ,
293+ documentName : document . name ,
294+ } ;
295+
296+ this . storeDocumentHooks ( document , storePayload ) ;
287297 }
288298
289299 /**
@@ -408,14 +418,24 @@ export class Hocuspocus<Context = any> {
408418 } ,
409419 ) ;
410420
411- document . awareness . on ( "update" , ( update : AwarenessUpdate ) => {
412- this . hooks ( "onAwarenessUpdate" , {
413- ...hookPayload ,
414- ...update ,
415- awareness : document . awareness ,
416- states : awarenessStatesToArray ( document . awareness . getStates ( ) ) ,
417- } ) ;
418- } ) ;
421+ document . awareness . on (
422+ "update" ,
423+ ( update : AwarenessUpdate , origin : unknown ) => {
424+ this . hooks ( "onAwarenessUpdate" , {
425+ document,
426+ documentName,
427+ instance : this ,
428+ ...update ,
429+ transactionOrigin : origin ,
430+ connection :
431+ isTransactionOrigin ( origin ) && origin . source === "connection"
432+ ? origin . connection
433+ : undefined ,
434+ awareness : document . awareness ,
435+ states : awarenessStatesToArray ( document . awareness . getStates ( ) ) ,
436+ } ) ;
437+ } ,
438+ ) ;
419439
420440 return document ;
421441 }
@@ -460,6 +480,7 @@ export class Hocuspocus<Context = any> {
460480 hooks < T extends HookName > (
461481 name : T ,
462482 payload : HookPayloadByName < Context > [ T ] ,
483+ // biome-ignore lint/complexity/noBannedTypes: <explanation>
463484 callback : Function | null = null ,
464485 ) : Promise < any > {
465486 const { extensions } = this . configuration ;
0 commit comments