UNPKG

@casual-simulation/aux-common

Version:
131 lines 4.59 kB
import type { BotsState, PartialBotsState } from '../bots/Bot'; import type { VersionVector } from '../common'; /** * The name of the property that indicates an object represents a tag edit. * Uses the Device Control One control character (UTF code 11) at the beginning to help prevent conflicts with normal property names. * Normally, we would use a Symbol, but symbols are not supported via structure clone which means that we have to use a normal property. */ export declare const TAG_EDIT_NAME = "\u0011tag_edit"; /** * Creates a tag edit using the given list of operations. */ export declare function edit(version: VersionVector, ...operations: TagEditOp[]): TagEdit; /** * Creates a tag edit using the given list of operations. */ export declare function remoteEdit(version: VersionVector, ...operations: TagEditOp[]): TagEdit; /** * Creates a tag edit using the given list of operations. */ export declare function edits(version: VersionVector, ...operations: TagEditOp[][]): TagEdit; /** * Creates a tag edit using the given list of operations. */ export declare function remoteEdits(version: VersionVector, ...operations: TagEditOp[][]): TagEdit; /** * Creates a new tag edit using the operations from both of the given edits. * @param first The first edit. * @param second The second edit. */ export declare function mergeEdits(first: TagEdit, second: TagEdit): TagEdit; /** * Creates a preserve operation that keeps the given number of characters. * @param count The number of characters to preserve. */ export declare function preserve(count: number): TagPreserveOp; /** * Creates a insert operation that inserts the given text. * @param text The text to insert. */ export declare function insert(text: string): TagInsertOp; /** * Creates a delete operation that deletes the text between the given start and end indexes. * @param count The number of characters to delete. */ export declare function del(count: number): TagDeleteOp; /** * Determines if the given value is a tag edit. * @param value The value to check. */ export declare function isTagEdit(value: any): value is TagEdit; /** * Merges the two version vectors, taking the latest timestamp from each. * @param first The first. * @param second The second. */ export declare function mergeVersions(first: VersionVector, second: VersionVector): VersionVector; /** * Defines an interface that represents a tag edit. */ export interface TagEdit { [TAG_EDIT_NAME]: boolean; /** * The timestamp that the edit should be made at. */ version: VersionVector; /** * Whether the edit should be considered a "remote" edit. * Remote edits should be processed by partitions as a separate site ID from the * local partition site ID. * This is useful for edits that were not made through the UI. */ isRemote?: boolean; /** * The operations that are part of the edit. */ operations: TagEditOp[][]; } export type TagEditOp = TagPreserveOp | TagInsertOp | TagDeleteOp; /** * A tag edit that represents the act of not changing some text in a tag's value. */ export interface TagPreserveOp { type: 'preserve'; /** * The number of characters to preserve. */ count: number; } /** * A tag edit that represents inserting some text into a tag's value. */ export interface TagInsertOp { type: 'insert'; /** * The text that should be inserted. */ text: string; } /** * A tag edit operation that represents deleting some text from a tag's value. */ export interface TagDeleteOp { type: 'delete'; /** * The number of characters to delete. */ count: number; } /** * Applies the given update to the current state and returns the final result. * @param state The state. * @param update The update. */ export declare function apply<T extends BotsState, U extends PartialBotsState>(state: T, update: U): T; /** * Applies the given tag edit to the given value and returns a value suitable for use in a tag. * i.e. This converts empty strings to null. * @param value The value to edit. * @param edit The edit to apply. * @returns */ export declare function applyTagEdit(value: any, edit: TagEdit): any; /** * Applies the edit to the given value and returns the result. * Unlike applyTagEdit(), this function only edits the value and returns the result. * As a result, * @param value The value. * @param edit The edit that should be applied. */ export declare function applyEdit(value: any, edit: TagEdit): any; //# sourceMappingURL=AuxStateHelpers.d.ts.map