import { IChannelAttributes , IFluidDataStoreRuntime , IChannelServices , IChannelFactory , } from "@fluidframework/datastore-definitions" ; import Delta from "quill-delta" ; import { SharedOT } from "../../dist" ; export class SharedDelta extends SharedOT < Delta , Delta > { public static create ( runtime , id ? ) { return runtime . createChannel ( id , DeltaFactory . Type ) as SharedDelta ; } public static getFactory ( ) { return new DeltaFactory ( ) ; } constructor ( id , runtime , attributes ) { super ( id , runtime , attributes , new Delta ( ) ) ; } public get delta ( ) : Delta { return this . state ; } public get text ( ) { return this . state . reduce ( ( s , delta ) => { return `${ s }${ delta . insert ?. toString ( ) }` ; } , "" ) ; } public get length ( ) { return this . text . length ; } protected transform ( input , transform ) { return new Delta ( transform ) . transform ( input , false ) ; } protected applyCore ( state , op ) { return state . compose ( op ) ; } public insert ( position , text ) { this . apply ( new Delta ( ) . retain ( position ) . insert ( text ) ) ; } public delete ( start , end ) { this . apply ( new Delta ( ) . retain ( start ) . delete ( end - start ) ) ; } } export class DeltaFactory implements IChannelFactory { public static Type = "@test/delta-factory" ; public static readonly Attributes : IChannelAttributes = { type : DeltaFactory . Type , snapshotFormatVersion : "test" , packageVersion : "test" } ; public get type ( ) { return DeltaFactory . Type ; } public get attributes ( ) { return DeltaFactory . Attributes ; } /**
     * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.load}
     */ public async load ( runtime , id , services , attributes ) { const instance = new SharedDelta ( id , runtime , attributes ) ; await instance . load ( services ) ; return instance ; } public create ( runtime , id ) { const instance = new SharedDelta ( id , runtime , this . attributes ) ; instance . initializeLocal ( ) ; return instance ; } }