Skip to content 

SharedString Class

Packages > @fluidframework/sequence > 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: SharedSegmentSequence<SharedStringSegment>

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 string
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 concensus.
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)
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 postition
insertMarkerRelative(relativePos1, refType, props) Inserts a marker at a relative postition
insertText(pos, text, props) Inserts the text at the postition
insertTextRelative(relativePos1, text, props) Inserts the text at the postition
removeText(start, end)
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 IFluidDataStoreRuntime
id string
attributes IChannelAttributes

Properties

id

Signature:

id: string;

ISharedString

Signature:

get ISharedString(): ISharedString;

Methods

annotateMarker

Annotates the marker with the provided properties

Signature:

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

Parameters

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

Returns:

void

annotateMarkerNotifyConsensus

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

Signature:

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

Parameters

List of parameters
Parameter Type Description
marker MergeTree.Marker The marker to annotate
props MergeTree.PropertySet The properties to annotate the marker with
callback (m: MergeTree.Marker) => void

Returns:

void

create

Create a new shared string

Signature:

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

Parameters

List of parameters
Parameter Type Description
runtime IFluidDataStoreRuntime data store runtime the new shared string belongs to
id string 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: MergeTree.ReferencePosition;
        pos: number;
    };

Parameters

List of parameters
Parameter Type Description
startPos number | undefined
tileLabel string
preceding boolean

Returns:

{ tile: MergeTree.ReferencePosition; pos: number; }

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): MergeTree.ISegment;

Parameters

List of parameters
Parameter Type Description
id string

Returns:

MergeTree.ISegment

getText

Signature:

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

Parameters

List of parameters
Parameter Type Description
start number
end number

Returns:

string

getTextAndMarkers

Signature:

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

Parameters

List of parameters
Parameter Type Description
label string

Returns:

{ parallelText: string[]; parallelMarkers: MergeTree.Marker[]; }

getTextRangeWithMarkers

Signature:

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

Parameters

List of parameters
Parameter Type Description
start number
end number

Returns:

string

getTextRangeWithPlaceholders

Signature:

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

Parameters

List of parameters
Parameter Type Description
start number
end number

Returns:

string

getTextWithPlaceholders

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

Signature:

getTextWithPlaceholders(): string;

Returns:

string

insertMarker

Inserts a marker at the postition

Signature:

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

Parameters

List of parameters
Parameter Type Description
pos number The postition to insert the marker at
refType MergeTree.ReferenceType The reference type of the marker
props MergeTree.PropertySet The properties of the marker

Returns:

MergeTree.IMergeTreeInsertMsg

insertMarkerRelative

Inserts a marker at a relative postition

Signature:

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

Parameters

List of parameters
Parameter Type Description
relativePos1 MergeTree.IRelativePosition The relative postition to insert the marker at
refType MergeTree.ReferenceType The reference type of the marker
props MergeTree.PropertySet The properties of the marker

Returns:

void

insertText

Inserts the text at the postition

Signature:

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

Parameters

List of parameters
Parameter Type Description
pos number The postition to insert the text at
text string The text to insert
props MergeTree.PropertySet The properties of text

Returns:

void

insertTextRelative

Inserts the text at the postition

Signature:

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

Parameters

List of parameters
Parameter Type Description
relativePos1 MergeTree.IRelativePosition The relative postition to insert the text at
text string The text to insert
props MergeTree.PropertySet The properties of text

Returns:

void

removeText

Signature:

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

Parameters

List of parameters
Parameter Type Description
start number
end number

Returns:

MergeTree.IMergeTreeRemoveMsg

replaceText

Replaces a range with the provided text.

Signature:

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

Parameters

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

Returns:

void