@fluidframework/sequence 2.83.0 → 2.90.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/api-report/sequence.legacy.beta.api.md +1 -1
- package/dist/intervalCollection.d.ts +3 -2
- package/dist/intervalCollection.d.ts.map +1 -1
- package/dist/intervalCollection.js +5 -5
- package/dist/intervalCollection.js.map +1 -1
- package/dist/intervalIndex/endpointInRangeIndex.d.ts +3 -3
- package/dist/intervalIndex/endpointInRangeIndex.d.ts.map +1 -1
- package/dist/intervalIndex/endpointInRangeIndex.js +5 -6
- package/dist/intervalIndex/endpointInRangeIndex.js.map +1 -1
- package/dist/intervalIndex/endpointIndex.d.ts +3 -3
- package/dist/intervalIndex/endpointIndex.d.ts.map +1 -1
- package/dist/intervalIndex/endpointIndex.js +5 -6
- package/dist/intervalIndex/endpointIndex.js.map +1 -1
- package/dist/intervalIndex/overlappingIntervalsIndex.d.ts +8 -7
- package/dist/intervalIndex/overlappingIntervalsIndex.d.ts.map +1 -1
- package/dist/intervalIndex/overlappingIntervalsIndex.js +5 -6
- package/dist/intervalIndex/overlappingIntervalsIndex.js.map +1 -1
- package/dist/intervalIndex/startpointInRangeIndex.d.ts +3 -3
- package/dist/intervalIndex/startpointInRangeIndex.d.ts.map +1 -1
- package/dist/intervalIndex/startpointInRangeIndex.js +5 -6
- package/dist/intervalIndex/startpointInRangeIndex.js.map +1 -1
- package/dist/intervals/index.d.ts +1 -1
- package/dist/intervals/index.d.ts.map +1 -1
- package/dist/intervals/index.js +4 -2
- package/dist/intervals/index.js.map +1 -1
- package/dist/intervals/sequenceInterval.d.ts +60 -35
- package/dist/intervals/sequenceInterval.d.ts.map +1 -1
- package/dist/intervals/sequenceInterval.js +166 -102
- package/dist/intervals/sequenceInterval.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/sequence.d.ts +3 -6
- package/dist/sequence.d.ts.map +1 -1
- package/dist/sequence.js +2 -5
- package/dist/sequence.js.map +1 -1
- package/lib/intervalCollection.d.ts +3 -2
- package/lib/intervalCollection.d.ts.map +1 -1
- package/lib/intervalCollection.js +5 -5
- package/lib/intervalCollection.js.map +1 -1
- package/lib/intervalIndex/endpointInRangeIndex.d.ts +3 -3
- package/lib/intervalIndex/endpointInRangeIndex.d.ts.map +1 -1
- package/lib/intervalIndex/endpointInRangeIndex.js +6 -7
- package/lib/intervalIndex/endpointInRangeIndex.js.map +1 -1
- package/lib/intervalIndex/endpointIndex.d.ts +3 -3
- package/lib/intervalIndex/endpointIndex.d.ts.map +1 -1
- package/lib/intervalIndex/endpointIndex.js +6 -7
- package/lib/intervalIndex/endpointIndex.js.map +1 -1
- package/lib/intervalIndex/overlappingIntervalsIndex.d.ts +8 -7
- package/lib/intervalIndex/overlappingIntervalsIndex.d.ts.map +1 -1
- package/lib/intervalIndex/overlappingIntervalsIndex.js +7 -8
- package/lib/intervalIndex/overlappingIntervalsIndex.js.map +1 -1
- package/lib/intervalIndex/startpointInRangeIndex.d.ts +3 -3
- package/lib/intervalIndex/startpointInRangeIndex.d.ts.map +1 -1
- package/lib/intervalIndex/startpointInRangeIndex.js +6 -7
- package/lib/intervalIndex/startpointInRangeIndex.js.map +1 -1
- package/lib/intervals/index.d.ts +1 -1
- package/lib/intervals/index.d.ts.map +1 -1
- package/lib/intervals/index.js +1 -1
- package/lib/intervals/index.js.map +1 -1
- package/lib/intervals/sequenceInterval.d.ts +60 -35
- package/lib/intervals/sequenceInterval.d.ts.map +1 -1
- package/lib/intervals/sequenceInterval.js +162 -100
- package/lib/intervals/sequenceInterval.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/sequence.d.ts +3 -6
- package/lib/sequence.d.ts.map +1 -1
- package/lib/sequence.js +2 -5
- package/lib/sequence.js.map +1 -1
- package/package.json +20 -20
- package/src/intervalCollection.ts +6 -3
- package/src/intervalIndex/endpointInRangeIndex.ts +11 -7
- package/src/intervalIndex/endpointIndex.ts +7 -7
- package/src/intervalIndex/overlappingIntervalsIndex.ts +18 -25
- package/src/intervalIndex/startpointInRangeIndex.ts +11 -7
- package/src/intervals/index.ts +3 -1
- package/src/intervals/sequenceInterval.ts +249 -124
- package/src/packageVersion.ts +1 -1
- package/src/sequence.ts +8 -11
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { PropertyAction, RedBlackTree } from "@fluidframework/merge-tree/internal";
|
|
7
7
|
|
|
8
|
-
import { SequenceInterval,
|
|
8
|
+
import { SequenceInterval, createTransientIntervalFromSequence } from "../intervals/index.js";
|
|
9
|
+
import type { ISharedSegmentSequence } from "../sequence.js";
|
|
9
10
|
import { ISharedString } from "../sharedString.js";
|
|
10
11
|
|
|
11
12
|
import type { SequenceIntervalIndex } from "./intervalIndex.js";
|
|
@@ -31,7 +32,7 @@ export interface IStartpointInRangeIndex extends SequenceIntervalIndex {
|
|
|
31
32
|
export class StartpointInRangeIndex implements IStartpointInRangeIndex {
|
|
32
33
|
private readonly intervalTree;
|
|
33
34
|
|
|
34
|
-
constructor(private readonly
|
|
35
|
+
constructor(private readonly sequence: ISharedSegmentSequence<any>) {
|
|
35
36
|
this.intervalTree = new RedBlackTree<SequenceInterval, SequenceInterval>(
|
|
36
37
|
(a: SequenceInterval, b: SequenceInterval) => {
|
|
37
38
|
const compareStartsResult = a.compareStart(b);
|
|
@@ -74,9 +75,13 @@ export class StartpointInRangeIndex implements IStartpointInRangeIndex {
|
|
|
74
75
|
return true;
|
|
75
76
|
};
|
|
76
77
|
|
|
77
|
-
const transientStartInterval =
|
|
78
|
+
const transientStartInterval = createTransientIntervalFromSequence(
|
|
79
|
+
start,
|
|
80
|
+
start,
|
|
81
|
+
this.sequence,
|
|
82
|
+
);
|
|
78
83
|
|
|
79
|
-
const transientEndInterval =
|
|
84
|
+
const transientEndInterval = createTransientIntervalFromSequence(end, end, this.sequence);
|
|
80
85
|
|
|
81
86
|
// Add comparison overrides to the transient intervals
|
|
82
87
|
(transientStartInterval as Partial<HasComparisonOverride>)[forceCompare] = -1;
|
|
@@ -94,6 +99,5 @@ export class StartpointInRangeIndex implements IStartpointInRangeIndex {
|
|
|
94
99
|
export function createStartpointInRangeIndex(
|
|
95
100
|
sharedString: ISharedString,
|
|
96
101
|
): IStartpointInRangeIndex {
|
|
97
|
-
|
|
98
|
-
return new StartpointInRangeIndex(client);
|
|
102
|
+
return new StartpointInRangeIndex(sharedString);
|
|
99
103
|
}
|
package/src/intervals/index.ts
CHANGED
|
@@ -19,8 +19,10 @@ export {
|
|
|
19
19
|
export {
|
|
20
20
|
SequenceInterval,
|
|
21
21
|
SequenceIntervalClass,
|
|
22
|
+
BaseSequenceInterval,
|
|
22
23
|
createSequenceInterval,
|
|
23
24
|
createPositionReferenceFromSegoff,
|
|
24
|
-
|
|
25
|
+
createTransientIntervalFromSequence,
|
|
26
|
+
resolvePositionRef,
|
|
25
27
|
getSerializedProperties,
|
|
26
28
|
} from "./sequenceInterval.js";
|
|
@@ -35,6 +35,8 @@ import {
|
|
|
35
35
|
import { LoggingError, UsageError } from "@fluidframework/telemetry-utils/internal";
|
|
36
36
|
import { v4 as uuid } from "uuid";
|
|
37
37
|
|
|
38
|
+
import type { ISharedSegmentSequence } from "../sequence.js";
|
|
39
|
+
|
|
38
40
|
import {
|
|
39
41
|
ISerializableInterval,
|
|
40
42
|
ISerializedInterval,
|
|
@@ -182,8 +184,148 @@ export interface SequenceInterval extends IInterval {
|
|
|
182
184
|
getIntervalId(): string;
|
|
183
185
|
}
|
|
184
186
|
|
|
187
|
+
/**
|
|
188
|
+
* Lightweight interval for index queries (overlap, comparison).
|
|
189
|
+
* Has no Client dependency; cannot serialize or be disposed.
|
|
190
|
+
*/
|
|
191
|
+
export class BaseSequenceInterval implements SequenceInterval, ISerializableInterval {
|
|
192
|
+
readonly #id: string;
|
|
193
|
+
readonly #properties: PropertySet = createMap<any>();
|
|
194
|
+
|
|
195
|
+
constructor(
|
|
196
|
+
id: string,
|
|
197
|
+
/**
|
|
198
|
+
* Start endpoint of this interval.
|
|
199
|
+
* @remarks This endpoint can be resolved into a character position using the SharedString it's a part of.
|
|
200
|
+
*/
|
|
201
|
+
public start: LocalReferencePosition,
|
|
202
|
+
/**
|
|
203
|
+
* End endpoint of this interval.
|
|
204
|
+
* @remarks This endpoint can be resolved into a character position using the SharedString it's a part of.
|
|
205
|
+
*/
|
|
206
|
+
public end: LocalReferencePosition,
|
|
207
|
+
public intervalType: IntervalType,
|
|
208
|
+
public readonly startSide: Side = Side.Before,
|
|
209
|
+
public readonly endSide: Side = Side.Before,
|
|
210
|
+
) {
|
|
211
|
+
this.#id = id;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
public get properties(): Readonly<PropertySet> {
|
|
215
|
+
return this.#properties;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/***/
|
|
219
|
+
public get stickiness(): IntervalStickiness {
|
|
220
|
+
this.verifyNotDispose();
|
|
221
|
+
|
|
222
|
+
const startSegment: ISegmentInternal | undefined = this.start.getSegment();
|
|
223
|
+
const endSegment: ISegmentInternal | undefined = this.end.getSegment();
|
|
224
|
+
return computeStickinessFromSide(
|
|
225
|
+
startSegment?.endpointType,
|
|
226
|
+
this.startSide,
|
|
227
|
+
endSegment?.endpointType,
|
|
228
|
+
this.endSide,
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* {@inheritDoc ISerializableInterval.getIntervalId}
|
|
234
|
+
*/
|
|
235
|
+
public getIntervalId(): string {
|
|
236
|
+
return this.#id;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* {@inheritDoc IInterval.compare}
|
|
241
|
+
*/
|
|
242
|
+
public compare(b: SequenceInterval) {
|
|
243
|
+
const startResult = this.compareStart(b);
|
|
244
|
+
if (startResult === 0) {
|
|
245
|
+
const endResult = this.compareEnd(b);
|
|
246
|
+
if (endResult === 0) {
|
|
247
|
+
const thisId = this.getIntervalId();
|
|
248
|
+
if (thisId) {
|
|
249
|
+
const bId = b.getIntervalId();
|
|
250
|
+
if (bId) {
|
|
251
|
+
return thisId > bId ? 1 : thisId < bId ? -1 : 0;
|
|
252
|
+
}
|
|
253
|
+
return 0;
|
|
254
|
+
}
|
|
255
|
+
return 0;
|
|
256
|
+
} else {
|
|
257
|
+
return endResult;
|
|
258
|
+
}
|
|
259
|
+
} else {
|
|
260
|
+
return startResult;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* {@inheritDoc IInterval.compareStart}
|
|
266
|
+
*/
|
|
267
|
+
public compareStart(b: SequenceInterval) {
|
|
268
|
+
this.verifyNotDispose();
|
|
269
|
+
|
|
270
|
+
const dist = compareReferencePositions(this.start, b.start);
|
|
271
|
+
|
|
272
|
+
if (dist === 0) {
|
|
273
|
+
return compareSides(this.startSide, b.startSide);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
return dist;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* {@inheritDoc IInterval.compareEnd}
|
|
281
|
+
*/
|
|
282
|
+
public compareEnd(b: SequenceInterval): number {
|
|
283
|
+
this.verifyNotDispose();
|
|
284
|
+
|
|
285
|
+
const dist = compareReferencePositions(this.end, b.end);
|
|
286
|
+
|
|
287
|
+
if (dist === 0) {
|
|
288
|
+
return compareSides(b.endSide, this.endSide);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
return dist;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* {@inheritDoc IInterval.overlaps}
|
|
296
|
+
*/
|
|
297
|
+
public overlaps(b: SequenceInterval) {
|
|
298
|
+
this.verifyNotDispose();
|
|
299
|
+
|
|
300
|
+
const result =
|
|
301
|
+
compareReferencePositions(this.start, b.end) <= 0 &&
|
|
302
|
+
compareReferencePositions(this.end, b.start) >= 0;
|
|
303
|
+
return result;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Whether this interval overlaps the provided numerical positions.
|
|
308
|
+
*/
|
|
309
|
+
public overlapsPos(_bstart: number, _bend: number): boolean {
|
|
310
|
+
assert(false, 0xcd7 /* overlapsPos not supported on BaseSequenceInterval */);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
public clone(): BaseSequenceInterval {
|
|
314
|
+
assert(false, 0xcd8 /* clone not supported on BaseSequenceInterval */);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
public union(_b: BaseSequenceInterval): BaseSequenceInterval {
|
|
318
|
+
assert(false, 0xcd9 /* union not supported on BaseSequenceInterval */);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
protected verifyNotDispose(): void {
|
|
322
|
+
// No-op: transient intervals are not disposable.
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
185
326
|
export class SequenceIntervalClass
|
|
186
|
-
|
|
327
|
+
extends BaseSequenceInterval
|
|
328
|
+
implements ISerializableInterval, IDisposable
|
|
187
329
|
{
|
|
188
330
|
readonly #props: {
|
|
189
331
|
propertyManager?: PropertiesManager;
|
|
@@ -193,7 +335,7 @@ export class SequenceIntervalClass
|
|
|
193
335
|
/**
|
|
194
336
|
* {@inheritDoc ISerializableInterval.properties}
|
|
195
337
|
*/
|
|
196
|
-
public get properties(): Readonly<PropertySet> {
|
|
338
|
+
public override get properties(): Readonly<PropertySet> {
|
|
197
339
|
this.verifyNotDispose();
|
|
198
340
|
return this.#props.properties;
|
|
199
341
|
}
|
|
@@ -220,39 +362,18 @@ export class SequenceIntervalClass
|
|
|
220
362
|
}
|
|
221
363
|
}
|
|
222
364
|
|
|
223
|
-
/***/
|
|
224
|
-
public get stickiness(): IntervalStickiness {
|
|
225
|
-
this.verifyNotDispose();
|
|
226
|
-
|
|
227
|
-
const startSegment: ISegmentInternal | undefined = this.start.getSegment();
|
|
228
|
-
const endSegment: ISegmentInternal | undefined = this.end.getSegment();
|
|
229
|
-
return computeStickinessFromSide(
|
|
230
|
-
startSegment?.endpointType,
|
|
231
|
-
this.startSide,
|
|
232
|
-
endSegment?.endpointType,
|
|
233
|
-
this.endSide,
|
|
234
|
-
);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
365
|
constructor(
|
|
238
366
|
private readonly client: Client,
|
|
239
|
-
|
|
367
|
+
id: string,
|
|
240
368
|
private readonly label: string,
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
*/
|
|
245
|
-
public start: LocalReferencePosition,
|
|
246
|
-
/**
|
|
247
|
-
* End endpoint of this interval.
|
|
248
|
-
* @remarks This endpoint can be resolved into a character position using the SharedString it's a part of.
|
|
249
|
-
*/
|
|
250
|
-
public end: LocalReferencePosition,
|
|
251
|
-
public intervalType: IntervalType,
|
|
369
|
+
start: LocalReferencePosition,
|
|
370
|
+
end: LocalReferencePosition,
|
|
371
|
+
intervalType: IntervalType,
|
|
252
372
|
props?: PropertySet,
|
|
253
|
-
|
|
254
|
-
|
|
373
|
+
startSide: Side = Side.Before,
|
|
374
|
+
endSide: Side = Side.Before,
|
|
255
375
|
) {
|
|
376
|
+
super(id, start, end, intervalType, startSide, endSide);
|
|
256
377
|
if (props) {
|
|
257
378
|
this.#props.properties = addProperties(this.#props.properties, props);
|
|
258
379
|
}
|
|
@@ -270,7 +391,7 @@ export class SequenceIntervalClass
|
|
|
270
391
|
this.#props.propertyManager = undefined;
|
|
271
392
|
}
|
|
272
393
|
|
|
273
|
-
|
|
394
|
+
protected override verifyNotDispose() {
|
|
274
395
|
if (this.#disposed) {
|
|
275
396
|
throw new LoggingError("Invalid interval access after dispose");
|
|
276
397
|
}
|
|
@@ -350,7 +471,7 @@ export class SequenceIntervalClass
|
|
|
350
471
|
endSide: includeEndpoints ? this.endSide : undefined,
|
|
351
472
|
properties: {
|
|
352
473
|
...props,
|
|
353
|
-
[reservedIntervalIdKey]: this.
|
|
474
|
+
[reservedIntervalIdKey]: this.getIntervalId(),
|
|
354
475
|
[reservedRangeLabelsKey]: [this.label],
|
|
355
476
|
},
|
|
356
477
|
} satisfies SerializedIntervalDelta;
|
|
@@ -364,7 +485,7 @@ export class SequenceIntervalClass
|
|
|
364
485
|
|
|
365
486
|
return new SequenceIntervalClass(
|
|
366
487
|
this.client,
|
|
367
|
-
this.
|
|
488
|
+
this.getIntervalId(),
|
|
368
489
|
this.label,
|
|
369
490
|
this.start,
|
|
370
491
|
this.end,
|
|
@@ -375,80 +496,6 @@ export class SequenceIntervalClass
|
|
|
375
496
|
);
|
|
376
497
|
}
|
|
377
498
|
|
|
378
|
-
/**
|
|
379
|
-
* {@inheritDoc IInterval.compare}
|
|
380
|
-
*/
|
|
381
|
-
public compare(b: SequenceInterval) {
|
|
382
|
-
const startResult = this.compareStart(b);
|
|
383
|
-
if (startResult === 0) {
|
|
384
|
-
const endResult = this.compareEnd(b);
|
|
385
|
-
if (endResult === 0) {
|
|
386
|
-
const thisId = this.getIntervalId();
|
|
387
|
-
if (thisId) {
|
|
388
|
-
const bId = b.getIntervalId();
|
|
389
|
-
if (bId) {
|
|
390
|
-
return thisId > bId ? 1 : thisId < bId ? -1 : 0;
|
|
391
|
-
}
|
|
392
|
-
return 0;
|
|
393
|
-
}
|
|
394
|
-
return 0;
|
|
395
|
-
} else {
|
|
396
|
-
return endResult;
|
|
397
|
-
}
|
|
398
|
-
} else {
|
|
399
|
-
return startResult;
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
/**
|
|
404
|
-
* {@inheritDoc IInterval.compareStart}
|
|
405
|
-
*/
|
|
406
|
-
public compareStart(b: SequenceInterval) {
|
|
407
|
-
this.verifyNotDispose();
|
|
408
|
-
|
|
409
|
-
const dist = compareReferencePositions(this.start, b.start);
|
|
410
|
-
|
|
411
|
-
if (dist === 0) {
|
|
412
|
-
return compareSides(this.startSide, b.startSide);
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
return dist;
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
/**
|
|
419
|
-
* {@inheritDoc IInterval.compareEnd}
|
|
420
|
-
*/
|
|
421
|
-
public compareEnd(b: SequenceInterval): number {
|
|
422
|
-
this.verifyNotDispose();
|
|
423
|
-
|
|
424
|
-
const dist = compareReferencePositions(this.end, b.end);
|
|
425
|
-
|
|
426
|
-
if (dist === 0) {
|
|
427
|
-
return compareSides(b.endSide, this.endSide);
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
return dist;
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
/**
|
|
434
|
-
* {@inheritDoc IInterval.overlaps}
|
|
435
|
-
*/
|
|
436
|
-
public overlaps(b: SequenceInterval) {
|
|
437
|
-
this.verifyNotDispose();
|
|
438
|
-
|
|
439
|
-
const result =
|
|
440
|
-
compareReferencePositions(this.start, b.end) <= 0 &&
|
|
441
|
-
compareReferencePositions(this.end, b.start) >= 0;
|
|
442
|
-
return result;
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
/**
|
|
446
|
-
* {@inheritDoc ISerializableInterval.getIntervalId}
|
|
447
|
-
*/
|
|
448
|
-
public getIntervalId(): string {
|
|
449
|
-
return this.id;
|
|
450
|
-
}
|
|
451
|
-
|
|
452
499
|
/**
|
|
453
500
|
* {@inheritDoc IInterval.union}
|
|
454
501
|
*/
|
|
@@ -490,7 +537,7 @@ export class SequenceIntervalClass
|
|
|
490
537
|
/**
|
|
491
538
|
* Whether this interval overlaps the provided numerical positions.
|
|
492
539
|
*/
|
|
493
|
-
public overlapsPos(bstart: number, bend: number) {
|
|
540
|
+
public override overlapsPos(bstart: number, bend: number) {
|
|
494
541
|
this.verifyNotDispose();
|
|
495
542
|
|
|
496
543
|
const startPos = this.client.localReferencePositionToPosition(this.start);
|
|
@@ -602,7 +649,7 @@ export class SequenceIntervalClass
|
|
|
602
649
|
|
|
603
650
|
const newInterval = new SequenceIntervalClass(
|
|
604
651
|
this.client,
|
|
605
|
-
this.
|
|
652
|
+
this.getIntervalId(),
|
|
606
653
|
this.label,
|
|
607
654
|
startRef,
|
|
608
655
|
endRef,
|
|
@@ -697,6 +744,41 @@ export function createPositionReferenceFromSegoff({
|
|
|
697
744
|
return createDetachedLocalReferencePosition(slidingPreference, refType);
|
|
698
745
|
}
|
|
699
746
|
|
|
747
|
+
/**
|
|
748
|
+
* Resolves a position to a {@link LocalReferencePosition} using an
|
|
749
|
+
* {@link ISharedSegmentSequence} (no Client or op context needed).
|
|
750
|
+
*/
|
|
751
|
+
export function resolvePositionRef(
|
|
752
|
+
sequence: ISharedSegmentSequence<any>,
|
|
753
|
+
pos: number | "start" | "end",
|
|
754
|
+
refType: ReferenceType,
|
|
755
|
+
slidingPreference: SlidingPreference,
|
|
756
|
+
canSlideToEndpoint?: boolean,
|
|
757
|
+
): LocalReferencePosition {
|
|
758
|
+
if (pos === "start" || pos === "end") {
|
|
759
|
+
return sequence.createLocalReferencePosition(
|
|
760
|
+
pos,
|
|
761
|
+
undefined,
|
|
762
|
+
refType,
|
|
763
|
+
undefined,
|
|
764
|
+
slidingPreference,
|
|
765
|
+
canSlideToEndpoint,
|
|
766
|
+
);
|
|
767
|
+
}
|
|
768
|
+
const segoff = sequence.getContainingSegment(pos);
|
|
769
|
+
if (segoff?.segment !== undefined && segoff?.offset !== undefined) {
|
|
770
|
+
return sequence.createLocalReferencePosition(
|
|
771
|
+
segoff.segment,
|
|
772
|
+
segoff.offset,
|
|
773
|
+
refType,
|
|
774
|
+
undefined,
|
|
775
|
+
slidingPreference,
|
|
776
|
+
canSlideToEndpoint,
|
|
777
|
+
);
|
|
778
|
+
}
|
|
779
|
+
return createDetachedLocalReferencePosition(slidingPreference, refType);
|
|
780
|
+
}
|
|
781
|
+
|
|
700
782
|
function createPositionReference({
|
|
701
783
|
client,
|
|
702
784
|
pos,
|
|
@@ -758,18 +840,61 @@ function createPositionReference({
|
|
|
758
840
|
});
|
|
759
841
|
}
|
|
760
842
|
|
|
761
|
-
|
|
843
|
+
/**
|
|
844
|
+
* Creates a transient interval using an `ISharedSegmentSequence` instead of a `Client`.
|
|
845
|
+
* This avoids coupling index classes to merge-tree internals.
|
|
846
|
+
*/
|
|
847
|
+
export function createTransientIntervalFromSequence(
|
|
762
848
|
start: SequencePlace | undefined,
|
|
763
849
|
end: SequencePlace | undefined,
|
|
764
|
-
|
|
765
|
-
) {
|
|
766
|
-
|
|
767
|
-
"
|
|
850
|
+
sequence: ISharedSegmentSequence<any>,
|
|
851
|
+
): BaseSequenceInterval {
|
|
852
|
+
const { startPos, startSide, endPos, endSide } = endpointPosAndSide(
|
|
853
|
+
start ?? "start",
|
|
854
|
+
end ?? "end",
|
|
855
|
+
);
|
|
856
|
+
assert(
|
|
857
|
+
startPos !== undefined &&
|
|
858
|
+
endPos !== undefined &&
|
|
859
|
+
startSide !== undefined &&
|
|
860
|
+
endSide !== undefined,
|
|
861
|
+
0xcda /* start and end cannot be undefined because they were not passed in as undefined */,
|
|
862
|
+
);
|
|
863
|
+
|
|
864
|
+
const startSlidingPref = startReferenceSlidingPreference(
|
|
865
|
+
startPos,
|
|
866
|
+
startSide,
|
|
867
|
+
endPos,
|
|
868
|
+
endSide,
|
|
869
|
+
);
|
|
870
|
+
const endSlidingPref = endReferenceSlidingPreference(startPos, startSide, endPos, endSide);
|
|
871
|
+
|
|
872
|
+
const startLref = resolvePositionRef(
|
|
873
|
+
sequence,
|
|
874
|
+
startPos,
|
|
875
|
+
ReferenceType.Transient,
|
|
876
|
+
startSlidingPref,
|
|
877
|
+
);
|
|
878
|
+
const endLref = resolvePositionRef(
|
|
879
|
+
sequence,
|
|
880
|
+
endPos,
|
|
881
|
+
ReferenceType.Transient,
|
|
882
|
+
endSlidingPref,
|
|
883
|
+
);
|
|
884
|
+
|
|
885
|
+
const rangeProp = {
|
|
886
|
+
[reservedRangeLabelsKey]: ["transient"],
|
|
887
|
+
};
|
|
888
|
+
startLref.addProperties(rangeProp);
|
|
889
|
+
endLref.addProperties(rangeProp);
|
|
890
|
+
|
|
891
|
+
return new BaseSequenceInterval(
|
|
768
892
|
uuid(),
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
client,
|
|
893
|
+
startLref,
|
|
894
|
+
endLref,
|
|
772
895
|
IntervalType.Transient,
|
|
896
|
+
startSide,
|
|
897
|
+
endSide,
|
|
773
898
|
);
|
|
774
899
|
}
|
|
775
900
|
|
|
@@ -824,6 +949,13 @@ export function createSequenceInterval(
|
|
|
824
949
|
endSide,
|
|
825
950
|
);
|
|
826
951
|
|
|
952
|
+
const endSlidingPreference = endReferenceSlidingPreference(
|
|
953
|
+
startPos,
|
|
954
|
+
startSide,
|
|
955
|
+
endPos,
|
|
956
|
+
endSide,
|
|
957
|
+
);
|
|
958
|
+
|
|
827
959
|
const startLref = createPositionReference({
|
|
828
960
|
client,
|
|
829
961
|
pos: startPos,
|
|
@@ -835,13 +967,6 @@ export function createSequenceInterval(
|
|
|
835
967
|
rollback,
|
|
836
968
|
});
|
|
837
969
|
|
|
838
|
-
const endSlidingPreference = endReferenceSlidingPreference(
|
|
839
|
-
startPos,
|
|
840
|
-
startSide,
|
|
841
|
-
endPos,
|
|
842
|
-
endSide,
|
|
843
|
-
);
|
|
844
|
-
|
|
845
970
|
const endLref = createPositionReference({
|
|
846
971
|
client,
|
|
847
972
|
pos: endPos,
|
package/src/packageVersion.ts
CHANGED
package/src/sequence.ts
CHANGED
|
@@ -142,14 +142,14 @@ export interface ISharedSegmentSequence<T extends ISegment>
|
|
|
142
142
|
/**
|
|
143
143
|
* Creates a `LocalReferencePosition` on this SharedString. If the refType does not include
|
|
144
144
|
* ReferenceType.Transient, the returned reference will be added to the localRefs on the provided segment.
|
|
145
|
-
* @param segment - Segment to add the local reference on
|
|
145
|
+
* @param segment - Segment to add the local reference on, or "start"/"end" for endpoint segments
|
|
146
146
|
* @param offset - Offset on the segment at which to place the local reference
|
|
147
147
|
* @param refType - ReferenceType for the created local reference
|
|
148
148
|
* @param properties - PropertySet to place on the created local reference
|
|
149
149
|
*/
|
|
150
150
|
createLocalReferencePosition(
|
|
151
|
-
segment: T,
|
|
152
|
-
offset: number,
|
|
151
|
+
segment: T | "start" | "end",
|
|
152
|
+
offset: number | undefined,
|
|
153
153
|
refType: ReferenceType,
|
|
154
154
|
properties: PropertySet | undefined,
|
|
155
155
|
slidingPreference?: SlidingPreference,
|
|
@@ -617,8 +617,8 @@ export abstract class SharedSegmentSequence<T extends ISegment>
|
|
|
617
617
|
}
|
|
618
618
|
|
|
619
619
|
public createLocalReferencePosition(
|
|
620
|
-
segment: T,
|
|
621
|
-
offset: number,
|
|
620
|
+
segment: T | "start" | "end",
|
|
621
|
+
offset: number | undefined,
|
|
622
622
|
refType: ReferenceType,
|
|
623
623
|
properties: PropertySet | undefined,
|
|
624
624
|
slidingPreference?: SlidingPreference,
|
|
@@ -865,10 +865,7 @@ export abstract class SharedSegmentSequence<T extends ISegment>
|
|
|
865
865
|
}
|
|
866
866
|
}
|
|
867
867
|
|
|
868
|
-
|
|
869
|
-
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.processMessagesCore}
|
|
870
|
-
*/
|
|
871
|
-
protected processMessagesCore(messagesCollection: IRuntimeMessageCollection): void {
|
|
868
|
+
protected override processMessagesCore(messagesCollection: IRuntimeMessageCollection): void {
|
|
872
869
|
const { envelope, local, messagesContent } = messagesCollection;
|
|
873
870
|
for (const messageContent of messagesContent) {
|
|
874
871
|
this.processMessage(envelope, messageContent, local);
|
|
@@ -1024,7 +1021,7 @@ export abstract class SharedSegmentSequence<T extends ISegment>
|
|
|
1024
1021
|
(key: string, local: boolean) => {
|
|
1025
1022
|
const intervalCollection = this.intervalCollections.get(key);
|
|
1026
1023
|
if (!intervalCollection.attached) {
|
|
1027
|
-
intervalCollection.attachGraph(this.client, key);
|
|
1024
|
+
intervalCollection.attachGraph(this, this.client, key);
|
|
1028
1025
|
}
|
|
1029
1026
|
this.emit("createIntervalCollection", key, local, this);
|
|
1030
1027
|
},
|
|
@@ -1033,7 +1030,7 @@ export abstract class SharedSegmentSequence<T extends ISegment>
|
|
|
1033
1030
|
// Initialize existing SharedIntervalCollections
|
|
1034
1031
|
for (const key of this.intervalCollections.keys()) {
|
|
1035
1032
|
const intervalCollection = this.intervalCollections.get(key);
|
|
1036
|
-
intervalCollection.attachGraph(this.client, key);
|
|
1033
|
+
intervalCollection.attachGraph(this, this.client, key);
|
|
1037
1034
|
}
|
|
1038
1035
|
}
|
|
1039
1036
|
|