import { IFluidDataStoreRuntime } from '@fluidframework/datastore-definitions' ; import { EditId } from '../Identifiers' ; import { Snapshot } from '../Snapshot' ; import { Edit , BuildNode , fullHistorySummarizer , GenericSharedTree , NodeData , SharedTreeSummaryBase } from '../generic' ; import { OrderedEditSet } from '../EditLog' ; import { noHistorySummarizer , revert } from '../default-edits' ; import { AnchoredChange , AnchoredDelete , AnchoredInsert , AnchoredMove , RangeAnchor , PlaceAnchor , NodeAnchor , } from './PersistedTypes' ; import { SharedTreeWithAnchorsFactory , SharedTreeWithAnchorsFactoryNoHistory } from './Factory' ; import { TransactionWithAnchors } from './TransactionWithAnchors' ; example public export class SharedTreeWithAnchorsEditor { private readonly tree : SharedTreeWithAnchors ; public constructor ( tree ) { this . tree = tree ; } param node param destination public insert ( node , destination ) ; param nodes param destination public insert ( nodes , destination ) ; public insert ( nodeOrNodes , destination ) { return this . tree . applyEdit ( ... AnchoredInsert . create ( Array . isArray ( nodeOrNodes ) ? nodeOrNodes : [ nodeOrNodes ] , destination ) ) ; } param source param destination public move ( source , destination ) ; param source param destination public move ( source , destination ) ; param source param destination public move ( source , destination ) ; public move ( source , destination ) { if ( ! this . isRange ( source ) ) { return this . tree . applyEdit ( ... AnchoredMove . create ( RangeAnchor . only ( source ) , destination ) ) ; } return this . tree . applyEdit ( ... AnchoredMove . create ( source , destination ) ) ; } param target public delete ( target ) ; param target public delete ( target ) ; param target public delete ( target ) ; public delete ( target ) { if ( ! this . isRange ( target ) ) { return this . tree . applyEdit ( AnchoredDelete . create ( RangeAnchor . only ( target ) ) ) ; } return this . tree . applyEdit ( AnchoredDelete . create ( target ) ) ; } param edit param view public revert ( edit , view ) { return this . tree . applyEdit ( ... revert ( edit . changes , view ) ) ; } public applyChanges ( changes ) { return this . tree . applyEdit ( ... changes ) ; } private isRange ( source ) { return ( source as RangeAnchor ) . start !== undefined && ( source as RangeAnchor ) . end !== undefined ; } } public sealed export class SharedTreeWithAnchors extends GenericSharedTree < AnchoredChange > { /**
     * Create a new SharedTreeWithAnchors. It will contain the default value (see initialTree).
     */ public static create ( runtime , id ? ) { return runtime . createChannel ( id , SharedTreeWithAnchorsFactory . Type ) as SharedTreeWithAnchors ; } param historySummarizing returns public static getFactory ( summarizeHistory = true ) { return summarizeHistory ? new SharedTreeWithAnchorsFactory ( ) : new SharedTreeWithAnchorsFactoryNoHistory ( ) ; } param runtime param id param expensiveValidation param summarizeHistory public constructor ( runtime , id , expensiveValidation = false , summarizeHistory = true ) { super ( runtime , id , TransactionWithAnchors . factory , SharedTreeWithAnchorsFactory . Attributes , expensiveValidation , summarizeHistory ) ; } private _editor : SharedTreeWithAnchorsEditor | undefined ; /**
     * Returns a `SharedTreeEditor` for editing this tree in an imperative fashion. All edits are performed on the current tree view.
     */ public get editor ( ) : SharedTreeWithAnchorsEditor { if ( ! this . _editor ) { this . _editor = new SharedTreeWithAnchorsEditor ( this ) ; } return this . _editor ; } /**
     * {@inheritDoc GenericSharedTree.generateSummary}
     */ protected generateSummary ( editLog ) { if ( ! this . summarizeHistory ) { return noHistorySummarizer ( editLog , this . currentView ) ; } return fullHistorySummarizer ( editLog , this . currentView ) ; } }