import { EditScript } from '@asmartbear/diff-merge'; import PackedBuffer from '../thunk/packed'; import AugmentedObjectManager, { AugmentedType } from './manager'; import { CompositeElement } from './composite'; import { IElement } from '.'; /** * Additional API available to Augmented Objects that hold collaborative text. */ export interface ICollaborativeText extends IElement { /** * Generates differential edit script, showing how to transform _from_ the current value _to_ the given `target` string. * In short, if these diffs are applied to the augmented object, it will be transformed into the `target`. */ createEdits(target: string): EditScript; } /** * Like `toElement()`, but specifically for collaborative text elements. Because those elements present as plain JavaScript * strings, this function takes a parent object and the field to access that contains the element, and returns its `ICollaborativeText` interface, * or `undefined` if that's not an object, or that's not collaborative text. */ export declare function toCollaborativeText(obj: any, field: string): ICollaborativeText | undefined; interface StringData { /** * Apparently a "character array," actually an AugmentedArray, so that if we're careful * with setting and splicing this array of characters, we get the collaborative editing * features "for free" from the Array implementation. */ chars: string[]; } declare class MyType implements AugmentedType { readonly name = "txt"; isNativeTypeCompatible(x: unknown): x is CollaborativePlainTextSentinal; createFromExisting(mgr: AugmentedObjectManager, ser: PackedBuffer | CollaborativePlainTextElement): CollaborativePlainTextElement; createFromNative(mgr: AugmentedObjectManager, x: CollaborativePlainTextSentinal): CollaborativePlainTextElement; } declare const MY_TYPE: MyType; export default MY_TYPE; /** * An element handling collaborative editing of plain-text, including support for generating and setting-by differences, * allowing for synchronizing between UI elements and the back-end, preserving intent. */ export declare class CollaborativePlainTextElement extends CompositeElement implements ICollaborativeText { get type(): MyType; toString(): string; get boolean(): boolean; get number(): number; get string(): string; valueOf(): any; toStateString(depth?: number): string; set(x: unknown): boolean; protected initialize(): void; createEdits(target: string): EditScript; } /** * The way to initialize a new Max scalar, is to instantiate one of these and add to a collection. * It will "melt away" immediately, appearing like a normal JavaScript Scalar which can only be increased. */ export declare class CollaborativePlainTextSentinal { readonly initialValue: string; constructor(initialValue: string); } /** * The way to initialize a new Collaborative Plain Text element, is to call this function and add to a collection. * It will "melt away" immediately, appearing like a normal JavaScript string. */ export declare function CollaborativePlainText(initialCounterValue?: string): string;