import { IRealtimeEdit } from "../api-calls/realtime-edit" ; import Delta from "quill-delta" ; param inputEdits param newEdit param countUserDeltas export const transformFromArray = ( inputEdits , newEdit , countUserDeltas ) : Delta | undefined => { const toBeTransformed = [ ] ; for ( let i = inputEdits . length - 1 ; i >= 0 ; i -- ) { const iRealtimeEdit = inputEdits [ i ] ; if ( iRealtimeEdit . serverGeneratedId === newEdit . prevServerGeneratedId ) { break ; } else if ( countUserDeltas || iRealtimeEdit . userId !== newEdit . userId ) { toBeTransformed . push ( iRealtimeEdit ) ; } } toBeTransformed . reverse ( ) ; let editDelta = undefined ; for ( const transformable of toBeTransformed ) { if ( ! editDelta ) { editDelta = new Delta ( transformable . delta ) ; } else { editDelta = editDelta . compose ( new Delta ( transformable . delta ) ) ; } } if ( editDelta && newEdit . delta ) { return editDelta . transform ( newEdit . delta , true ) ; } else { return newEdit . delta ; } } ;