/*! * Copyright (c) Microsoft Corporation and contributors. All rights reserved. * Licensed under the MIT License. */ import type { IDisposable } from "@fluidframework/core-interfaces"; import type { ISequencedDocumentMessage } from "@fluidframework/driver-definitions/internal"; import type { Client, ISegment, LocalReferencePosition, PropertySet, SequencePlace } from "@fluidframework/merge-tree/internal"; import { ReferenceType, SlidingPreference, Side } from "@fluidframework/merge-tree/internal"; import type { ISharedSegmentSequence } from "../sequence.js"; import type { ISerializableInterval, ISerializedInterval } from "./intervalUtils.js"; import { IntervalStickiness, IntervalType, type IInterval, type SerializedIntervalDelta } from "./intervalUtils.js"; export declare function getSerializedProperties(serializedInterval: ISerializedInterval | SerializedIntervalDelta): { id: string; labels: string[]; properties: PropertySet; }; /** * Interval implementation whose ends are associated with positions in a mutatable sequence. * As such, when content is inserted into the middle of the interval, the interval expands to * include that content. * * @remarks The endpoints' positions should be treated exclusively to get * reasonable behavior. E.g., an interval referring to "hello" in "hello world" * should have a start position of 0 and an end position of 5. * * To see why, consider what happens if "llo wor" is removed from the string to make "held". * The interval's startpoint remains on the "h" (it isn't altered), but the interval's endpoint * slides forward to the next unremoved position, which is the "l" in "held". * Users would generally expect the interval to now refer to "he" (as it is the subset of content * remaining after the removal), hence the "l" should be excluded. * If the interval endpoint was treated inclusively, the interval would now refer to "hel", which * is undesirable. * * Since the endpoints of an interval are treated exclusively but cannot be greater * than or equal to the length of the associated sequence, there exist special * endpoint segments, "start" and "end", which represent the position immediately * before or immediately after the string respectively. * * If a `SequenceInterval` is created on a sequence with the * `mergeTreeReferencesCanSlideToEndpoint` feature flag set to true, the endpoints * of the interval that are exclusive will have the ability to slide to these * special endpoint segments. * @legacy @beta */ export interface SequenceInterval extends IInterval { readonly start: LocalReferencePosition; /** * End endpoint of this interval. * @remarks This endpoint can be resolved into a character position using the SharedString it's a part of. */ readonly end: LocalReferencePosition; readonly intervalType: IntervalType; readonly startSide: Side; readonly endSide: Side; readonly stickiness: IntervalStickiness; /** Serializable bag of properties associated with the interval. */ properties: PropertySet; /** * Compares this interval to `b` with standard comparator semantics: * - returns -1 if this is less than `b` * - returns 1 if this is greater than `b` * - returns 0 if this is equivalent to `b` * @param b - Interval to compare against */ compare(b: SequenceInterval): number; /** * Compares the start endpoint of this interval to `b`'s start endpoint. * Standard comparator semantics apply. * @param b - Interval to compare against */ compareStart(b: SequenceInterval): number; /** * Compares the end endpoint of this interval to `b`'s end endpoint. * Standard comparator semantics apply. * @param b - Interval to compare against */ compareEnd(b: SequenceInterval): number; /** * @returns whether this interval overlaps with `b`. * Intervals are considered to overlap if their intersection is non-empty. */ overlaps(b: SequenceInterval): boolean; /** * @returns whether this interval overlaps two numerical positions. */ overlapsPos(bstart: number, bend: number): boolean; /** * Gets the id associated with this interval. * When the interval is used as part of an interval collection, this id can be used to modify or remove the * interval. */ getIntervalId(): string; } /** * Lightweight interval for index queries (overlap, comparison). * Has no Client dependency; cannot serialize or be disposed. */ export declare class BaseSequenceInterval implements SequenceInterval, ISerializableInterval { #private; /** * Start endpoint of this interval. * @remarks This endpoint can be resolved into a character position using the SharedString it's a part of. */ start: LocalReferencePosition; /** * End endpoint of this interval. * @remarks This endpoint can be resolved into a character position using the SharedString it's a part of. */ end: LocalReferencePosition; intervalType: IntervalType; readonly startSide: Side; readonly endSide: Side; constructor(id: string, /** * Start endpoint of this interval. * @remarks This endpoint can be resolved into a character position using the SharedString it's a part of. */ start: LocalReferencePosition, /** * End endpoint of this interval. * @remarks This endpoint can be resolved into a character position using the SharedString it's a part of. */ end: LocalReferencePosition, intervalType: IntervalType, startSide?: Side, endSide?: Side); get properties(): Readonly; /***/ get stickiness(): IntervalStickiness; getIntervalId(): string; compare(b: SequenceInterval): number; compareStart(b: SequenceInterval): number; compareEnd(b: SequenceInterval): number; overlaps(b: SequenceInterval): boolean; /** * Whether this interval overlaps the provided numerical positions. */ overlapsPos(_bstart: number, _bend: number): boolean; clone(): BaseSequenceInterval; protected verifyNotDispose(): void; } export declare class SequenceIntervalClass extends BaseSequenceInterval implements ISerializableInterval, IDisposable { #private; private readonly client; private readonly label; get properties(): Readonly; changeProperties(props: PropertySet | undefined, op?: ISequencedDocumentMessage, rollback?: boolean): import("@fluidframework/merge-tree", { with: { "resolution-mode": "import" } }).MapLike | undefined; constructor(client: Client, id: string, label: string, start: LocalReferencePosition, end: LocalReferencePosition, intervalType: IntervalType, props?: PropertySet, startSide?: Side, endSide?: Side); get disposed(): boolean; dispose(error?: Error): void; protected verifyNotDispose(): void; private callbacks?; /** * Subscribes to position change events on this interval if there are no current listeners. */ addPositionChangeListeners(beforePositionChange: () => void, afterPositionChange: () => void): void; /** * Removes the currently subscribed position change listeners. */ removePositionChangeListeners(): void; serialize(): ISerializedInterval; serializeDelta({ props, includeEndpoints, }: { props: PropertySet | undefined; includeEndpoints: boolean; }): SerializedIntervalDelta; clone(): SequenceIntervalClass; /** * Whether this interval overlaps the provided numerical positions. */ overlapsPos(bstart: number, bend: number): boolean; moveEndpointReferences(rebased: Record<"start" | "end", { segment: ISegment; offset: number; }>): void; /** * {@inheritDoc IInterval.modify} */ modify(label: string, start: SequencePlace | undefined, end: SequencePlace | undefined, op?: ISequencedDocumentMessage, localSeq?: number, canSlideToEndpoint?: boolean): SequenceIntervalClass; ackPropertiesChange(newProps: PropertySet, op: ISequencedDocumentMessage): void; } export declare function createPositionReferenceFromSegoff({ client, segoff, refType, op, localSeq, fromSnapshot, slidingPreference, canSlideToEndpoint, rollback, }: { client: Client; segoff: { segment: ISegment; offset: number; } | undefined | "start" | "end"; refType: ReferenceType; op?: ISequencedDocumentMessage; localSeq?: number; fromSnapshot?: boolean; slidingPreference: SlidingPreference | undefined; canSlideToEndpoint: boolean | undefined; rollback?: boolean; }): LocalReferencePosition; /** * Resolves a position to a {@link LocalReferencePosition} using an * {@link ISharedSegmentSequence} (no Client or op context needed). */ export declare function resolvePositionRef(sequence: ISharedSegmentSequence, pos: number | "start" | "end", refType: ReferenceType, slidingPreference: SlidingPreference, canSlideToEndpoint?: boolean): LocalReferencePosition; /** * Creates a transient interval using an `ISharedSegmentSequence` instead of a `Client`. * This avoids coupling index classes to merge-tree internals. */ export declare function createTransientIntervalFromSequence(start: SequencePlace | undefined, end: SequencePlace | undefined, sequence: ISharedSegmentSequence): BaseSequenceInterval; export declare function createSequenceInterval(label: string, id: string, start: SequencePlace | undefined, end: SequencePlace | undefined, client: Client, intervalType: IntervalType, op?: ISequencedDocumentMessage, fromSnapshot?: boolean, canSlideToEndpoint?: boolean, props?: PropertySet, rollback?: boolean): SequenceIntervalClass; //# sourceMappingURL=sequenceInterval.d.ts.map