SharedString Class

Packages > fluid-framework > SharedString

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.

Signature:

export declare class SharedString extends SharedSegmentSequence<SharedStringSegment> implements ISharedString 

Extends: SharedSegmentSequenceSharedStringSegment

Implements: ISharedString

Constructors

List of constructors for this class
Constructor Modifiers Description
(constructor)(document, id, attributes) Constructs a new instance of the SharedString class

Properties

List of properties for this class
Property Modifiers Type Description
id
ISharedString ISharedString

Methods

List of methods on this class
Method Modifiers Description
annotateMarker(marker, props, combiningOp) Annotates the marker with the provided properties.
annotateMarkerNotifyConsensus(marker, props, callback) Annotates the marker with the provided properties and calls the callback on consensus.
create(runtime, id) static Create a new shared string.
findTile(startPos, tileLabel, preceding)
getFactory() static Get a factory for SharedString to register with the data store.
getMarkerFromId(id)
getText(start, end) Retrieve text from the SharedString in string format.
getTextAndMarkers(label)
getTextRangeWithMarkers(start, end)
getTextRangeWithPlaceholders(start, end)
getTextWithPlaceholders() Adds spaces for markers and handles, so that position calculations account for them.
insertMarker(pos, refType, props) Inserts a marker at the position.
insertMarkerRelative(relativePos1, refType, props) Inserts a marker at a relative position.
insertText(pos, text, props) Inserts the text at the position.
insertTextRelative(relativePos1, text, props) Inserts the text at the position.
removeText(start, end) Removes the text in the given range.
replaceText(start, end, text, props) Replaces a range with the provided text.

Constructors

SharedString.(constructor)

Constructs a new instance of the SharedString class

Signature:

constructor(document: IFluidDataStoreRuntime, id: string, attributes: IChannelAttributes);

Parameters

List of parameters
Parameter Type Description
document
id
attributes

Properties

id

Signature:

id: string;

ISharedString

Signature:

get ISharedString(): ISharedString;

Methods

annotateMarker

Annotates the marker with the provided properties.

Signature:

annotateMarker(marker: Marker, props: PropertySet, combiningOp?: ICombiningOp): void;

Parameters

List of parameters
Parameter Type Description
marker The marker to annotate
props The properties to annotate the marker with
combiningOp Optional. Specifies how to combine values for the property, such as "incr" for increment.

Returns:

annotateMarkerNotifyConsensus

Annotates the marker with the provided properties and calls the callback on consensus.

Signature:

annotateMarkerNotifyConsensus(marker: Marker, props: PropertySet, callback: (m: Marker) => void): void;

Parameters

List of parameters
Parameter Type Description
marker The marker to annotate
props The properties to annotate the marker with
callback

Returns:

create

Create a new shared string.

Signature:

static create(runtime: IFluidDataStoreRuntime, id?: string): SharedString;

Parameters

List of parameters
Parameter Type Description
runtime data store runtime the new shared string belongs to
id optional name of the shared string

Returns:

SharedString

newly create shared string (but not attached yet)

findTile

Signature:

findTile(startPos: number | undefined, tileLabel: string, preceding?: boolean): {
        tile: ReferencePosition;
        pos: number;
    };

Parameters

List of parameters
Parameter Type Description
startPos
tileLabel
preceding

Returns:

getFactory

Get a factory for SharedString to register with the data store.

Signature:

static getFactory(): SharedStringFactory;

Returns:

SharedStringFactory

a factory that creates and load SharedString

getMarkerFromId

Signature:

getMarkerFromId(id: string): ISegment;

Parameters

List of parameters
Parameter Type Description
id

Returns:

getText

Retrieve text from the SharedString in string format.

Signature:

getText(start?: number, end?: number): string;

Parameters

List of parameters
Parameter Type Description
start The starting index of the text to retrieve, or 0 if omitted.
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.

getTextAndMarkers

Signature:

getTextAndMarkers(label: string): {
        parallelText: string[];
        parallelMarkers: Marker[];
    };

Parameters

List of parameters
Parameter Type Description
label

Returns:

getTextRangeWithMarkers

Signature:

getTextRangeWithMarkers(start: number, end: number): string;

Parameters

List of parameters
Parameter Type Description
start
end

Returns:

getTextRangeWithPlaceholders

Signature:

getTextRangeWithPlaceholders(start: number, end: number): string;

Parameters

List of parameters
Parameter Type Description
start
end

Returns:

getTextWithPlaceholders

Adds spaces for markers and handles, so that position calculations account for them.

Signature:

getTextWithPlaceholders(): string;

Returns:

insertMarker

Inserts a marker at the position.

Signature:

insertMarker(pos: number, refType: ReferenceType, props?: PropertySet): IMergeTreeInsertMsg;

Parameters

List of parameters
Parameter Type Description
pos The position to insert the marker at
refType The reference type of the marker
props The properties of the marker

Returns:

insertMarkerRelative

Inserts a marker at a relative position.

Signature:

insertMarkerRelative(relativePos1: IRelativePosition, refType: ReferenceType, props?: PropertySet): void;

Parameters

List of parameters
Parameter Type Description
relativePos1 The relative position to insert the marker at
refType The reference type of the marker
props The properties of the marker

Returns:

insertText

Inserts the text at the position.

Signature:

insertText(pos: number, text: string, props?: PropertySet): void;

Parameters

List of parameters
Parameter Type Description
pos The position to insert the text at
text The text to insert
props The properties of the text

Returns:

insertTextRelative

Inserts the text at the position.

Signature:

insertTextRelative(relativePos1: IRelativePosition, text: string, props?: PropertySet): void;

Parameters

List of parameters
Parameter Type Description
relativePos1 The relative position to insert the text at
text The text to insert
props The properties of text

Returns:

removeText

Removes the text in the given range.

Signature:

removeText(start: number, end: number): IMergeTreeRemoveMsg;

Parameters

List of parameters
Parameter Type Description
start The inclusive start of the range to remove
end The exclusive end of the range to replace

Returns:

the message sent.

replaceText

Replaces a range with the provided text.

Signature:

replaceText(start: number, end: number, text: string, props?: PropertySet): void;

Parameters

List of parameters
Parameter Type Description
start The inclusive start of the range to replace
end The exclusive end of the range to replace
text The text to replace the range with
props Optional. The properties of the replacement text

Returns: