feat(editor): add isLocal flag in blockUpdated subject (#10799)

This commit is contained in:
Saul-Mirone
2025-03-13 05:33:06 +00:00
parent c023b724d0
commit 250f3f1efd
15 changed files with 167 additions and 119 deletions
@@ -2,7 +2,7 @@ import * as Y from 'yjs';
import { NATIVE_UNIQ_IDENTIFIER } from '../consts.js';
export type OnBoxedChange = (data: unknown) => void;
export type OnBoxedChange = (data: unknown, isLocal: boolean) => void;
export class Boxed<T = unknown> {
static from = <T>(map: Y.Map<T>, onChange?: OnBoxedChange): Boxed<T> => {
@@ -44,8 +44,17 @@ export class Boxed<T = unknown> {
this._map.set('type', NATIVE_UNIQ_IDENTIFIER as T);
this._map.set('value', value);
}
this._map.observeDeep(() => {
this._onChange?.(this.getValue());
this._map.observeDeep(events => {
events.forEach(event => {
const isLocal =
!event.transaction.origin ||
!this._map.doc ||
event.transaction.origin instanceof Y.UndoManager ||
event.transaction.origin.proxy
? true
: event.transaction.origin === this._map.doc.clientID;
this._onChange?.(this.getValue(), isLocal);
});
});
}