/*! * Copyright (c) Microsoft Corporation and contributors. All rights reserved. * Licensed under the MIT License. */ import type { IChannelAttributes, IFluidDataStoreRuntime } from "@fluidframework/datastore-definitions/internal"; import type { IRelativePosition, ISegment, PropertySet, ReferenceType } from "@fluidframework/merge-tree/internal"; import { Marker, TextSegment } from "@fluidframework/merge-tree/internal"; import { SharedSegmentSequence, type ISharedSegmentSequence } from "./sequence.js"; import { type SharedStringOptions } from "./sequenceFactory.js"; /** * Fluid object interface describing access methods on a SharedString * @legacy @beta */ export interface ISharedString extends ISharedSegmentSequence { /** * Inserts the text at the position. * @param pos - The position to insert the text at * @param text - The text to insert * @param props - The properties of the text */ insertText(pos: number, text: string, props?: PropertySet): void; /** * Inserts a marker at the position. * @param pos - The position to insert the marker at * @param refType - The reference type of the marker * @param props - The properties of the marker */ insertMarker(pos: number, refType: ReferenceType, props?: PropertySet): void; /** * Inserts a marker at a relative position. * @param relativePos1 - The relative position to insert the marker at * @param refType - The reference type of the marker * @param props - The properties of the marker */ insertMarkerRelative(relativePos1: IRelativePosition, refType: ReferenceType, props?: PropertySet): void; /** * Inserts the text at the position. * @param relativePos1 - The relative position to insert the text at * @param text - The text to insert * @param props - The properties of text */ insertTextRelative(relativePos1: IRelativePosition, text: string, props?: PropertySet): void; /** * Replaces a range with the provided text. * @param start - The inclusive start of the range to replace * @param end - The exclusive end of the range to replace * @param text - The text to replace the range with * @param props - Optional. The properties of the replacement text */ replaceText(start: number, end: number, text: string, props?: PropertySet): void; /** * Removes the text in the given range. * @param start - The inclusive start of the range to remove * @param end - The exclusive end of the range to replace * @returns the message sent. */ removeText(start: number, end: number): void; /** * Annotates the marker with the provided properties. * @param marker - The marker to annotate * @param props - The properties to annotate the marker with */ annotateMarker(marker: Marker, props: PropertySet): void; /** * Searches a string for the nearest marker in either direction to a given start position. * The search will include the start position, so markers at the start position are valid * results of the search. * @param startPos - Position at which to start the search * @param markerLabel - Label of the marker to search for * @param forwards - Whether the desired marker comes before (false) or after (true) `startPos`. Default true. */ searchForMarker(startPos: number, markerLabel: string, forwards?: boolean): Marker | undefined; /** * Retrieve text from the SharedString in string format. * @param start - The starting index of the text to retrieve, or 0 if omitted. * @param end - The ending index of the text to retrieve, or the end of the string if omitted * @returns The requested text content as a string. */ getText(start?: number, end?: number): string; /** * Adds spaces for markers and handles, so that position calculations account for them. */ getTextWithPlaceholders(start?: number, end?: number): string; getTextRangeWithMarkers(start: number, end: number): string; /** * Looks up and returns a `Marker` using its id. Returns `undefined` if there is no marker with the provided * id in this `SharedString`. */ getMarkerFromId(id: string): ISegment | undefined; } /** * @legacy @beta */ export type SharedStringSegment = TextSegment | Marker; /** * The Shared String is a specialized data structure for handling collaborative * text. It is based on a more general Sequence data structure but has * additional features that make working with text easier. * * In addition to text, a Shared String can also contain markers. Markers can be * used to store metadata at positions within the text, like the details of an * image or Fluid object that should be rendered with the text. * @internal */ export declare class SharedStringClass extends SharedSegmentSequence implements ISharedString { id: string; get ISharedString(): ISharedString; private readonly mergeTreeTextHelper; constructor(document: IFluidDataStoreRuntime, id: string, attributes: IChannelAttributes, options?: SharedStringOptions); insertMarkerRelative(relativePos1: IRelativePosition, refType: ReferenceType, props?: PropertySet): void; insertMarker(pos: number, refType: ReferenceType, props?: PropertySet): void; insertTextRelative(relativePos1: IRelativePosition, text: string, props?: PropertySet): void; insertText(pos: number, text: string, props?: PropertySet): void; replaceText(start: number, end: number, text: string, props?: PropertySet): void; removeText(start: number, end: number): void; annotateMarker(marker: Marker, props: PropertySet): void; searchForMarker(startPos: number, markerLabel: string, forwards?: boolean): Marker | undefined; getText(start?: number, end?: number): string; getTextWithPlaceholders(start?: number, end?: number): string; getTextRangeWithMarkers(start: number, end: number): string; getMarkerFromId(id: string): ISegment | undefined; } /** * Splits the text into regions ending with markers with the given `label`. * @param sharedString - String to retrieve text and markers from * @param label - label to split on * @returns Two parallel lists of text and markers, split by markers with the provided `label`. * For example: * ```typescript * // Say sharedstring has contents "helloworldmissing". * const { parallelText, parallelMarkers } = getTextAndMarkers(sharedString, "paragraph"); * // parallelText === ["hello", "world"] * // parallelMarkers === [, ] * // Note parallelText does not include "missing". * ``` * @internal */ export declare function getTextAndMarkers(sharedString: ISharedString, label: string, start?: number, end?: number): { parallelText: string[]; parallelMarkers: Marker[]; }; //# sourceMappingURL=sharedString.d.ts.map