@fluidframework/sequence 2.0.0-dev.4.4.0.162574 → 2.0.0-dev.5.3.2.178189

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.
Files changed (107) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/dist/defaultMap.d.ts +3 -2
  3. package/dist/defaultMap.d.ts.map +1 -1
  4. package/dist/defaultMap.js +4 -3
  5. package/dist/defaultMap.js.map +1 -1
  6. package/dist/defaultMapInterfaces.d.ts +12 -1
  7. package/dist/defaultMapInterfaces.d.ts.map +1 -1
  8. package/dist/defaultMapInterfaces.js.map +1 -1
  9. package/dist/index.d.ts +4 -2
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +17 -3
  12. package/dist/index.js.map +1 -1
  13. package/dist/intervalCollection.d.ts +240 -78
  14. package/dist/intervalCollection.d.ts.map +1 -1
  15. package/dist/intervalCollection.js +313 -190
  16. package/dist/intervalCollection.js.map +1 -1
  17. package/dist/intervalIndex/index.d.ts +8 -0
  18. package/dist/intervalIndex/index.d.ts.map +1 -0
  19. package/dist/intervalIndex/index.js +12 -0
  20. package/dist/intervalIndex/index.js.map +1 -0
  21. package/dist/intervalIndex/overlappingIntervalsIndex.d.ts +32 -0
  22. package/dist/intervalIndex/overlappingIntervalsIndex.d.ts.map +1 -0
  23. package/dist/intervalIndex/overlappingIntervalsIndex.js +103 -0
  24. package/dist/intervalIndex/overlappingIntervalsIndex.js.map +1 -0
  25. package/dist/intervalIndex/overlappingSequenceIntervalsIndex.d.ts +8 -0
  26. package/dist/intervalIndex/overlappingSequenceIntervalsIndex.d.ts.map +1 -0
  27. package/dist/intervalIndex/overlappingSequenceIntervalsIndex.js +33 -0
  28. package/dist/intervalIndex/overlappingSequenceIntervalsIndex.js.map +1 -0
  29. package/dist/intervalIndex/sequenceIntervalIndexes.d.ts +33 -0
  30. package/dist/intervalIndex/sequenceIntervalIndexes.d.ts.map +1 -0
  31. package/dist/intervalIndex/sequenceIntervalIndexes.js +7 -0
  32. package/dist/intervalIndex/sequenceIntervalIndexes.js.map +1 -0
  33. package/dist/packageVersion.d.ts +1 -1
  34. package/dist/packageVersion.js +1 -1
  35. package/dist/packageVersion.js.map +1 -1
  36. package/dist/revertibles.d.ts +104 -0
  37. package/dist/revertibles.d.ts.map +1 -0
  38. package/dist/revertibles.js +414 -0
  39. package/dist/revertibles.js.map +1 -0
  40. package/dist/sequence.d.ts +4 -4
  41. package/dist/sequence.d.ts.map +1 -1
  42. package/dist/sequence.js +3 -3
  43. package/dist/sequence.js.map +1 -1
  44. package/dist/sharedIntervalCollection.d.ts +3 -3
  45. package/dist/sharedIntervalCollection.d.ts.map +1 -1
  46. package/dist/sharedIntervalCollection.js +1 -1
  47. package/dist/sharedIntervalCollection.js.map +1 -1
  48. package/dist/tsdoc-metadata.json +11 -0
  49. package/lib/defaultMap.d.ts +3 -2
  50. package/lib/defaultMap.d.ts.map +1 -1
  51. package/lib/defaultMap.js +4 -3
  52. package/lib/defaultMap.js.map +1 -1
  53. package/lib/defaultMapInterfaces.d.ts +12 -1
  54. package/lib/defaultMapInterfaces.d.ts.map +1 -1
  55. package/lib/defaultMapInterfaces.js.map +1 -1
  56. package/lib/index.d.ts +4 -2
  57. package/lib/index.d.ts.map +1 -1
  58. package/lib/index.js +3 -1
  59. package/lib/index.js.map +1 -1
  60. package/lib/intervalCollection.d.ts +240 -78
  61. package/lib/intervalCollection.d.ts.map +1 -1
  62. package/lib/intervalCollection.js +310 -190
  63. package/lib/intervalCollection.js.map +1 -1
  64. package/lib/intervalIndex/index.d.ts +8 -0
  65. package/lib/intervalIndex/index.d.ts.map +1 -0
  66. package/lib/intervalIndex/index.js +7 -0
  67. package/lib/intervalIndex/index.js.map +1 -0
  68. package/lib/intervalIndex/overlappingIntervalsIndex.d.ts +32 -0
  69. package/lib/intervalIndex/overlappingIntervalsIndex.d.ts.map +1 -0
  70. package/lib/intervalIndex/overlappingIntervalsIndex.js +98 -0
  71. package/lib/intervalIndex/overlappingIntervalsIndex.js.map +1 -0
  72. package/lib/intervalIndex/overlappingSequenceIntervalsIndex.d.ts +8 -0
  73. package/lib/intervalIndex/overlappingSequenceIntervalsIndex.d.ts.map +1 -0
  74. package/lib/intervalIndex/overlappingSequenceIntervalsIndex.js +29 -0
  75. package/lib/intervalIndex/overlappingSequenceIntervalsIndex.js.map +1 -0
  76. package/lib/intervalIndex/sequenceIntervalIndexes.d.ts +33 -0
  77. package/lib/intervalIndex/sequenceIntervalIndexes.d.ts.map +1 -0
  78. package/lib/intervalIndex/sequenceIntervalIndexes.js +6 -0
  79. package/lib/intervalIndex/sequenceIntervalIndexes.js.map +1 -0
  80. package/lib/packageVersion.d.ts +1 -1
  81. package/lib/packageVersion.js +1 -1
  82. package/lib/packageVersion.js.map +1 -1
  83. package/lib/revertibles.d.ts +104 -0
  84. package/lib/revertibles.d.ts.map +1 -0
  85. package/lib/revertibles.js +404 -0
  86. package/lib/revertibles.js.map +1 -0
  87. package/lib/sequence.d.ts +4 -4
  88. package/lib/sequence.d.ts.map +1 -1
  89. package/lib/sequence.js +3 -3
  90. package/lib/sequence.js.map +1 -1
  91. package/lib/sharedIntervalCollection.d.ts +3 -3
  92. package/lib/sharedIntervalCollection.d.ts.map +1 -1
  93. package/lib/sharedIntervalCollection.js +1 -1
  94. package/lib/sharedIntervalCollection.js.map +1 -1
  95. package/package.json +22 -24
  96. package/src/defaultMap.ts +4 -1
  97. package/src/defaultMapInterfaces.ts +13 -1
  98. package/src/index.ts +27 -5
  99. package/src/intervalCollection.ts +660 -216
  100. package/src/intervalIndex/index.ts +11 -0
  101. package/src/intervalIndex/overlappingIntervalsIndex.ts +166 -0
  102. package/src/intervalIndex/overlappingSequenceIntervalsIndex.ts +71 -0
  103. package/src/intervalIndex/sequenceIntervalIndexes.ts +32 -0
  104. package/src/packageVersion.ts +1 -1
  105. package/src/revertibles.ts +626 -0
  106. package/src/sequence.ts +12 -2
  107. package/src/sharedIntervalCollection.ts +4 -2
@@ -0,0 +1,404 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ /* eslint-disable no-bitwise */
6
+ var __rest = (this && this.__rest) || function (s, e) {
7
+ var t = {};
8
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
9
+ t[p] = s[p];
10
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
11
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
12
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
13
+ t[p[i]] = s[p[i]];
14
+ }
15
+ return t;
16
+ };
17
+ import { assert, unreachableCase } from "@fluidframework/common-utils";
18
+ import { appendToMergeTreeDeltaRevertibles, discardMergeTreeDeltaRevertible, isMergeTreeDeltaRevertible, MergeTreeDeltaType, ReferenceType, refTypeIncludesFlag, revertMergeTreeDeltaRevertibles, SortedSet, getSlideToSegoff, } from "@fluidframework/merge-tree";
19
+ import { IntervalOpType, SequenceInterval } from "./intervalCollection";
20
+ const idMap = new Map();
21
+ function getUpdatedIdFromInterval(interval) {
22
+ const maybeId = interval.getIntervalId();
23
+ return getUpdatedId(maybeId);
24
+ }
25
+ function getUpdatedId(intervalId) {
26
+ var _a;
27
+ return (_a = idMap.get(intervalId)) !== null && _a !== void 0 ? _a : intervalId;
28
+ }
29
+ /**
30
+ * Create revertibles for adding an interval
31
+ * @alpha
32
+ */
33
+ export function appendAddIntervalToRevertibles(interval, revertibles) {
34
+ revertibles.push({
35
+ event: IntervalOpType.ADD,
36
+ interval,
37
+ });
38
+ return revertibles;
39
+ }
40
+ /**
41
+ * Create revertibles for deleting an interval
42
+ * @alpha
43
+ */
44
+ export function appendDeleteIntervalToRevertibles(string, interval, revertibles) {
45
+ const startSeg = interval.start.getSegment();
46
+ const startType = startSeg.removedSeq !== undefined
47
+ ? ReferenceType.SlideOnRemove | ReferenceType.RangeBegin
48
+ : ReferenceType.StayOnRemove | ReferenceType.RangeBegin;
49
+ const endSeg = interval.end.getSegment();
50
+ const endType = endSeg.removedSeq !== undefined
51
+ ? ReferenceType.SlideOnRemove | ReferenceType.RangeEnd
52
+ : ReferenceType.StayOnRemove | ReferenceType.RangeEnd;
53
+ const startRef = string.createLocalReferencePosition(startSeg, interval.start.getOffset(), startType, undefined, interval.start.slidingPreference);
54
+ const endRef = string.createLocalReferencePosition(endSeg, interval.end.getOffset(), endType, undefined, interval.end.slidingPreference);
55
+ const revertible = {
56
+ event: IntervalOpType.DELETE,
57
+ interval,
58
+ start: startRef,
59
+ end: endRef,
60
+ };
61
+ revertible.start.addProperties({ revertible });
62
+ revertible.end.addProperties({ revertible });
63
+ revertibles.push(revertible);
64
+ return revertibles;
65
+ }
66
+ /**
67
+ * Create revertibles for moving endpoints of an interval
68
+ * @alpha
69
+ */
70
+ export function appendChangeIntervalToRevertibles(string, newInterval, previousInterval, revertibles) {
71
+ const startSeg = previousInterval.start.getSegment();
72
+ // This logic is needed because the ReferenceType StayOnRemove cannot be used
73
+ // on removed segments. This works for revertibles because the old position of the
74
+ // interval within the removed segment is handled by the remove range revertible.
75
+ const startType = startSeg.removedSeq !== undefined
76
+ ? ReferenceType.SlideOnRemove | ReferenceType.RangeBegin
77
+ : ReferenceType.StayOnRemove | ReferenceType.RangeBegin;
78
+ const endSeg = previousInterval.end.getSegment();
79
+ const endType = endSeg.removedSeq !== undefined
80
+ ? ReferenceType.SlideOnRemove | ReferenceType.RangeEnd
81
+ : ReferenceType.StayOnRemove | ReferenceType.RangeEnd;
82
+ const prevStartRef = string.createLocalReferencePosition(startSeg, previousInterval.start.getOffset(), startType, undefined, previousInterval.start.slidingPreference);
83
+ const prevEndRef = string.createLocalReferencePosition(endSeg, previousInterval.end.getOffset(), endType, undefined, previousInterval.end.slidingPreference);
84
+ const revertible = {
85
+ event: IntervalOpType.CHANGE,
86
+ interval: newInterval,
87
+ start: prevStartRef,
88
+ end: prevEndRef,
89
+ };
90
+ revertible.start.addProperties({ revertible });
91
+ revertible.end.addProperties({ revertible });
92
+ revertibles.push(revertible);
93
+ return revertibles;
94
+ }
95
+ /**
96
+ * Create revertibles for changing properties of an interval
97
+ * @alpha
98
+ */
99
+ export function appendIntervalPropertyChangedToRevertibles(interval, deltas, revertibles) {
100
+ revertibles.push({
101
+ event: IntervalOpType.PROPERTY_CHANGED,
102
+ interval,
103
+ propertyDeltas: deltas,
104
+ });
105
+ return revertibles;
106
+ }
107
+ function addIfIntervalEndpoint(ref, segmentLengths, startIntervals, endIntervals) {
108
+ var _a, _b;
109
+ if (refTypeIncludesFlag(ref.refType, ReferenceType.RangeBegin)) {
110
+ const interval = (_a = ref.properties) === null || _a === void 0 ? void 0 : _a.interval;
111
+ if (interval && interval instanceof SequenceInterval) {
112
+ startIntervals.push({ offset: segmentLengths + interval.start.getOffset(), interval });
113
+ return true;
114
+ }
115
+ }
116
+ else if (refTypeIncludesFlag(ref.refType, ReferenceType.RangeEnd)) {
117
+ const interval = (_b = ref.properties) === null || _b === void 0 ? void 0 : _b.interval;
118
+ if (interval && interval instanceof SequenceInterval) {
119
+ endIntervals.push({ offset: segmentLengths + interval.end.getOffset(), interval });
120
+ return true;
121
+ }
122
+ }
123
+ return false;
124
+ }
125
+ function addIfRevertibleRef(ref, segmentLengths, revertibleRefs) {
126
+ var _a;
127
+ const revertible = (_a = ref.properties) === null || _a === void 0 ? void 0 : _a.revertible;
128
+ if (revertible) {
129
+ revertibleRefs.push({
130
+ revertible,
131
+ offset: segmentLengths + ref.getOffset(),
132
+ isStart: refTypeIncludesFlag(ref.refType, ReferenceType.RangeBegin),
133
+ });
134
+ }
135
+ }
136
+ /**
137
+ * Create revertibles for SharedStringDeltas, handling indirectly modified intervals
138
+ * (e.g. reverting remove of a range that contains an interval will move the interval back)
139
+ *
140
+ * Revertibles are new and require the option mergeTreeUseNewLengthCalculations to
141
+ * be set as true on the underlying merge tree in order to function correctly.
142
+ *
143
+ * @alpha
144
+ */
145
+ export function appendSharedStringDeltaToRevertibles(string, delta, revertibles) {
146
+ if (delta.ranges.length === 0) {
147
+ return;
148
+ }
149
+ if (delta.deltaOperation === MergeTreeDeltaType.REMOVE) {
150
+ const startIntervals = [];
151
+ const endIntervals = [];
152
+ const revertibleRefs = [];
153
+ let segmentLengths = 0;
154
+ // find interval endpoints in each segment
155
+ for (const deltaRange of delta.ranges) {
156
+ const refs = deltaRange.segment.localRefs;
157
+ if (refs !== undefined && deltaRange.position !== -1) {
158
+ for (const ref of refs) {
159
+ addIfIntervalEndpoint(ref, segmentLengths, startIntervals, endIntervals);
160
+ addIfRevertibleRef(ref, segmentLengths, revertibleRefs);
161
+ }
162
+ }
163
+ segmentLengths += deltaRange.segment.cachedLength;
164
+ }
165
+ if (startIntervals.length > 0 || endIntervals.length > 0 || revertibleRefs.length > 0) {
166
+ const removeRevertibles = [];
167
+ appendToMergeTreeDeltaRevertibles(delta.deltaArgs, removeRevertibles);
168
+ assert(removeRevertibles.length === 1, 0x6c4 /* Remove revertible should be a single delta */);
169
+ const revertible = {
170
+ event: IntervalOpType.POSITION_REMOVE,
171
+ intervals: [],
172
+ revertibleRefs,
173
+ mergeTreeRevertible: removeRevertibles[0],
174
+ };
175
+ // add an interval for each startInterval, accounting for any corresponding endIntervals
176
+ startIntervals.forEach(({ interval, offset }) => {
177
+ // find any corresponding end for this interval
178
+ const endIntervalIndex = endIntervals.findIndex((end) => {
179
+ return end.interval === interval;
180
+ });
181
+ let endOffset;
182
+ if (endIntervalIndex !== -1) {
183
+ endOffset = endIntervals[endIntervalIndex].offset;
184
+ endIntervals.splice(endIntervalIndex, 1);
185
+ }
186
+ revertible.intervals.push({
187
+ intervalId: interval.getIntervalId(),
188
+ label: interval.properties.referenceRangeLabels[0],
189
+ startOffset: offset,
190
+ endOffset,
191
+ });
192
+ });
193
+ // add any remaining endIntervals that aren't matched with a startInterval
194
+ endIntervals.forEach(({ interval, offset }) => {
195
+ revertible.intervals.push({
196
+ intervalId: interval.getIntervalId(),
197
+ label: interval.properties.referenceRangeLabels[0],
198
+ endOffset: offset,
199
+ });
200
+ });
201
+ revertibles.push(revertible);
202
+ return;
203
+ }
204
+ }
205
+ // Handle any merge tree delta that is not REMOVE or is REMOVE with no interval endpoints
206
+ const mergeTreeRevertibles = [];
207
+ // Allow merging MergeTreeDeltaRevertible with previous
208
+ if (revertibles.length > 0 && isMergeTreeDeltaRevertible(revertibles[revertibles.length - 1])) {
209
+ mergeTreeRevertibles.push(revertibles.pop());
210
+ }
211
+ appendToMergeTreeDeltaRevertibles(delta.deltaArgs, mergeTreeRevertibles);
212
+ revertibles.push(...mergeTreeRevertibles);
213
+ }
214
+ /**
215
+ * Clean up resources held by revertibles that are no longer needed.
216
+ * @alpha
217
+ */
218
+ export function discardSharedStringRevertibles(sharedString, revertibles) {
219
+ revertibles.forEach((r) => {
220
+ if (isMergeTreeDeltaRevertible(r)) {
221
+ discardMergeTreeDeltaRevertible([r]);
222
+ }
223
+ else if (r.event === IntervalOpType.CHANGE || r.event === IntervalOpType.DELETE) {
224
+ sharedString.removeLocalReferencePosition(r.start);
225
+ sharedString.removeLocalReferencePosition(r.end);
226
+ }
227
+ });
228
+ }
229
+ function getSlidePosition(string, lref, pos) {
230
+ const slide = getSlideToSegoff({ segment: lref.getSegment(), offset: undefined }, lref.slidingPreference);
231
+ return (slide === null || slide === void 0 ? void 0 : slide.segment) !== undefined &&
232
+ slide.offset !== undefined &&
233
+ string.getPosition(slide.segment) !== -1 &&
234
+ (pos < 0 || pos >= string.getLength())
235
+ ? string.getPosition(slide.segment) + slide.offset
236
+ : pos;
237
+ }
238
+ function isValidRange(start, end, string) {
239
+ return (start >= 0 &&
240
+ start < string.getLength() &&
241
+ end >= 0 &&
242
+ end < string.getLength() &&
243
+ start <= end);
244
+ }
245
+ function revertLocalAdd(string, revertible) {
246
+ const id = getUpdatedIdFromInterval(revertible.interval);
247
+ const label = revertible.interval.properties.referenceRangeLabels[0];
248
+ string.getIntervalCollection(label).removeIntervalById(id);
249
+ }
250
+ function revertLocalDelete(string, revertible) {
251
+ const label = revertible.interval.properties.referenceRangeLabels[0];
252
+ const collection = string.getIntervalCollection(label);
253
+ const start = string.localReferencePositionToPosition(revertible.start);
254
+ const startSlidePos = getSlidePosition(string, revertible.start, start);
255
+ const end = string.localReferencePositionToPosition(revertible.end);
256
+ const endSlidePos = getSlidePosition(string, revertible.end, end);
257
+ const type = revertible.interval.intervalType;
258
+ // reusing the id causes eventual consistency bugs, so it is removed here and recreated in add
259
+ const _a = revertible.interval.properties, { intervalId } = _a, props = __rest(_a, ["intervalId"]);
260
+ if (!isValidRange(startSlidePos, endSlidePos, string))
261
+ return;
262
+ const int = collection.add(startSlidePos, endSlidePos, type, props);
263
+ idMap.forEach((newId, oldId) => {
264
+ if (intervalId === newId) {
265
+ idMap.set(oldId, getUpdatedIdFromInterval(int));
266
+ }
267
+ });
268
+ idMap.set(intervalId, int.getIntervalId());
269
+ string.removeLocalReferencePosition(revertible.start);
270
+ string.removeLocalReferencePosition(revertible.end);
271
+ }
272
+ function revertLocalChange(string, revertible) {
273
+ const label = revertible.interval.properties.referenceRangeLabels[0];
274
+ const collection = string.getIntervalCollection(label);
275
+ const id = getUpdatedIdFromInterval(revertible.interval);
276
+ const start = string.localReferencePositionToPosition(revertible.start);
277
+ const startSlidePos = getSlidePosition(string, revertible.start, start);
278
+ const end = string.localReferencePositionToPosition(revertible.end);
279
+ const endSlidePos = getSlidePosition(string, revertible.end, end);
280
+ if (!isValidRange(startSlidePos, endSlidePos, string))
281
+ return;
282
+ collection.change(id, startSlidePos, endSlidePos);
283
+ string.removeLocalReferencePosition(revertible.start);
284
+ string.removeLocalReferencePosition(revertible.end);
285
+ }
286
+ function revertLocalPropertyChanged(string, revertible) {
287
+ const label = revertible.interval.properties.referenceRangeLabels[0];
288
+ const id = getUpdatedIdFromInterval(revertible.interval);
289
+ const newProps = revertible.propertyDeltas;
290
+ string.getIntervalCollection(label).changeProperties(id, newProps);
291
+ }
292
+ function newPosition(offset, restoredRanges) {
293
+ if (offset === undefined) {
294
+ return undefined;
295
+ }
296
+ let offsetFromSegment = offset;
297
+ for (const rangeInfo of restoredRanges.items) {
298
+ if (offsetFromSegment < rangeInfo.length) {
299
+ // find the segment inside the range
300
+ for (const range of rangeInfo.ranges) {
301
+ if (range.segment.cachedLength > offsetFromSegment) {
302
+ return { segment: range.segment, offset: offsetFromSegment };
303
+ }
304
+ offsetFromSegment -= range.segment.cachedLength;
305
+ }
306
+ }
307
+ offsetFromSegment -= rangeInfo.length;
308
+ }
309
+ return undefined;
310
+ }
311
+ function newEndpointPosition(offset, restoredRanges, sharedString) {
312
+ const pos = newPosition(offset, restoredRanges);
313
+ return pos === undefined ? undefined : sharedString.getPosition(pos.segment) + pos.offset;
314
+ }
315
+ class SortedRangeSet extends SortedSet {
316
+ getKey(item) {
317
+ return item.ranges[0].segment.ordinal;
318
+ }
319
+ }
320
+ function revertLocalSequenceRemove(sharedString, revertible) {
321
+ const restoredRanges = new SortedRangeSet();
322
+ const saveSegments = (event) => {
323
+ if (event.ranges.length > 0) {
324
+ let length = 0;
325
+ event.ranges.forEach((range) => {
326
+ length += range.segment.cachedLength;
327
+ });
328
+ restoredRanges.addOrUpdate({ ranges: event.ranges, length });
329
+ }
330
+ };
331
+ sharedString.on("sequenceDelta", saveSegments);
332
+ revertMergeTreeDeltaRevertibles(sharedString, [revertible.mergeTreeRevertible]);
333
+ sharedString.off("sequenceDelta", saveSegments);
334
+ revertible.intervals.forEach((intervalInfo) => {
335
+ const intervalCollection = sharedString.getIntervalCollection(intervalInfo.label);
336
+ const intervalId = getUpdatedId(intervalInfo.intervalId);
337
+ const interval = intervalCollection.getIntervalById(intervalId);
338
+ if (interval !== undefined) {
339
+ const newStart = newEndpointPosition(intervalInfo.startOffset, restoredRanges, sharedString);
340
+ const newEnd = newEndpointPosition(intervalInfo.endOffset, restoredRanges, sharedString);
341
+ if (newStart !== undefined || newEnd !== undefined) {
342
+ intervalCollection.change(intervalId, newStart, newEnd);
343
+ }
344
+ }
345
+ });
346
+ // fix up the local references used by delete and change revertibles
347
+ revertible.revertibleRefs.forEach((revertibleRef) => {
348
+ assert(revertibleRef.revertible.event === IntervalOpType.CHANGE ||
349
+ revertibleRef.revertible.event === IntervalOpType.DELETE, 0x6c5 /* revertible is not delete or change */);
350
+ const pos = newPosition(revertibleRef.offset, restoredRanges);
351
+ if (pos !== undefined) {
352
+ if (revertibleRef.isStart) {
353
+ sharedString.removeLocalReferencePosition(revertibleRef.revertible.start);
354
+ const newRef = sharedString.createLocalReferencePosition(pos.segment, pos.offset, ReferenceType.StayOnRemove | ReferenceType.RangeBegin, { revertible: revertibleRef.revertible });
355
+ revertibleRef.revertible.start = newRef;
356
+ }
357
+ else {
358
+ sharedString.removeLocalReferencePosition(revertibleRef.revertible.end);
359
+ const newRef = sharedString.createLocalReferencePosition(pos.segment, pos.offset, ReferenceType.StayOnRemove | ReferenceType.RangeEnd, { revertible: revertibleRef.revertible });
360
+ revertibleRef.revertible.end = newRef;
361
+ }
362
+ }
363
+ });
364
+ }
365
+ /**
366
+ * Invoke revertibles to reverse prior edits
367
+ *
368
+ * Revertibles are new and require the option mergeTreeUseNewLengthCalculations to
369
+ * be set as true on the underlying merge tree in order to function correctly.
370
+ *
371
+ * @alpha
372
+ */
373
+ export function revertSharedStringRevertibles(sharedString, revertibles) {
374
+ while (revertibles.length > 0) {
375
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
376
+ const r = revertibles.pop();
377
+ if ("event" in r) {
378
+ const event = r.event;
379
+ switch (event) {
380
+ case IntervalOpType.ADD:
381
+ revertLocalAdd(sharedString, r);
382
+ break;
383
+ case IntervalOpType.DELETE:
384
+ revertLocalDelete(sharedString, r);
385
+ break;
386
+ case IntervalOpType.CHANGE:
387
+ revertLocalChange(sharedString, r);
388
+ break;
389
+ case IntervalOpType.PROPERTY_CHANGED:
390
+ revertLocalPropertyChanged(sharedString, r);
391
+ break;
392
+ case IntervalOpType.POSITION_REMOVE:
393
+ revertLocalSequenceRemove(sharedString, r);
394
+ break;
395
+ default:
396
+ unreachableCase(event);
397
+ }
398
+ }
399
+ else {
400
+ revertMergeTreeDeltaRevertibles(sharedString, [r]);
401
+ }
402
+ }
403
+ }
404
+ //# sourceMappingURL=revertibles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"revertibles.js","sourceRoot":"","sources":["../src/revertibles.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,+BAA+B;;;;;;;;;;;;AAE/B,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,EACN,iCAAiC,EACjC,+BAA+B,EAC/B,0BAA0B,EAI1B,kBAAkB,EAElB,aAAa,EACb,mBAAmB,EACnB,+BAA+B,EAC/B,SAAS,EACT,gBAAgB,GAChB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAcxE,MAAM,KAAK,GAAG,IAAI,GAAG,EAAkB,CAAC;AAqDxC,SAAS,wBAAwB,CAAC,QAA0B;IAC3D,MAAM,OAAO,GAAG,QAAQ,CAAC,aAAa,EAAE,CAAC;IACzC,OAAO,YAAY,CAAC,OAAO,CAAC,CAAC;AAC9B,CAAC;AAED,SAAS,YAAY,CAAC,UAAkB;;IACvC,OAAO,MAAA,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,mCAAI,UAAU,CAAC;AAC5C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,8BAA8B,CAC7C,QAA0B,EAC1B,WAAqC;IAErC,WAAW,CAAC,IAAI,CAAC;QAChB,KAAK,EAAE,cAAc,CAAC,GAAG;QACzB,QAAQ;KACR,CAAC,CAAC;IAEH,OAAO,WAAW,CAAC;AACpB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iCAAiC,CAChD,MAAoB,EACpB,QAA0B,EAC1B,WAAqC;IAErC,MAAM,QAAQ,GAAG,QAAQ,CAAC,K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,CAAC,MAAM,GAAG,CAAC,EAAE;QAC9B,oEAAoE;QACpE,MAAM,CAAC,GAAG,WAAW,CAAC,GAAG,EAAG,CAAC;QAC7B,IAAI,OAAO,IAAI,CAAC,EAAE;YACjB,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC;YACtB,QAAQ,KAAK,EAAE;gBACd,KAAK,cAAc,CAAC,GAAG;oBACtB,cAAc,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;oBAChC,MAAM;gBACP,KAAK,cAAc,CAAC,MAAM;oBACzB,iBAAiB,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;oBACnC,MAAM;gBACP,KAAK,cAAc,CAAC,MAAM;oBACzB,iBAAiB,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;oBACnC,MAAM;gBACP,KAAK,cAAc,CAAC,gBAAgB;oBACnC,0BAA0B,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;oBAC5C,MAAM;gBACP,KAAK,cAAc,CAAC,eAAe;oBAClC,yBAAyB,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;oBAC3C,MAAM;gBACP;oBACC,eAAe,CAAC,KAAK,CAAC,CAAC;aACxB;SACD;aAAM;YACN,+BAA+B,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;SACnD;KACD;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n/* eslint-disable no-bitwise */\n\nimport { assert, unreachableCase } from \"@fluidframework/common-utils\";\nimport {\n\tappendToMergeTreeDeltaRevertibles,\n\tdiscardMergeTreeDeltaRevertible,\n\tisMergeTreeDeltaRevertible,\n\tLocalReferencePosition,\n\tMergeTreeDeltaOperationType,\n\tMergeTreeDeltaRevertible,\n\tMergeTreeDeltaType,\n\tPropertySet,\n\tReferenceType,\n\trefTypeIncludesFlag,\n\trevertMergeTreeDeltaRevertibles,\n\tSortedSet,\n\tgetSlideToSegoff,\n} from \"@fluidframework/merge-tree\";\nimport { IntervalOpType, SequenceInterval } from \"./intervalCollection\";\nimport { SharedString, SharedStringSegment } from \"./sharedString\";\nimport { ISequenceDeltaRange, SequenceDeltaEvent } from \"./sequenceDeltaEvent\";\n\n/**\n * Data for undoing edits on SharedStrings and Intervals.\n *\n * Revertibles are new and require the option mergeTreeUseNewLengthCalculations to\n * be set as true on the underlying merge tree in order to function correctly.\n *\n * @alpha\n */\nexport type SharedStringRevertible = MergeTreeDeltaRevertible | IntervalRevertible;\n\nconst idMap = new Map<string, string>();\n\ntype IntervalOpType = typeof IntervalOpType[keyof typeof IntervalOpType];\n\n/**\n * Data for undoing edits affecting Intervals.\n *\n * Revertibles are new and require the option mergeTreeUseNewLengthCalculations to\n * be set as true on the underlying merge tree in order to function correctly.\n *\n * @alpha\n */\nexport type IntervalRevertible =\n\t| {\n\t\t\tevent: typeof IntervalOpType.CHANGE;\n\t\t\tinterval: SequenceInterval;\n\t\t\tstart: LocalReferencePosition;\n\t\t\tend: LocalReferencePosition;\n\t }\n\t| {\n\t\t\tevent: typeof IntervalOpType.ADD;\n\t\t\tinterval: SequenceInterval;\n\t }\n\t| {\n\t\t\tevent: typeof IntervalOpType.DELETE;\n\t\t\tinterval: SequenceInterval;\n\t\t\tstart: LocalReferencePosition;\n\t\t\tend: LocalReferencePosition;\n\t }\n\t| {\n\t\t\tevent: typeof IntervalOpType.PROPERTY_CHANGED;\n\t\t\tinterval: SequenceInterval;\n\t\t\tpropertyDeltas: PropertySet;\n\t }\n\t| {\n\t\t\tevent: typeof IntervalOpType.POSITION_REMOVE;\n\t\t\tintervals: {\n\t\t\t\tintervalId: string;\n\t\t\t\tlabel: string;\n\t\t\t\tstartOffset?: number; // interval start index within a removed range\n\t\t\t\tendOffset?: number; // interval end index within a removed range\n\t\t\t}[];\n\t\t\t// local refs used by IntervalOpType.CHANGE and DELETE revertibles\n\t\t\trevertibleRefs: {\n\t\t\t\trevertible: IntervalRevertible;\n\t\t\t\toffset: number;\n\t\t\t\tisStart: boolean;\n\t\t\t}[];\n\t\t\tmergeTreeRevertible: MergeTreeDeltaRevertible;\n\t };\n\ntype TypedRevertible<T extends IntervalRevertible[\"event\"]> = IntervalRevertible & { event: T };\n\nfunction getUpdatedIdFromInterval(interval: SequenceInterval): string {\n\tconst maybeId = interval.getIntervalId();\n\treturn getUpdatedId(maybeId);\n}\n\nfunction getUpdatedId(intervalId: string): string {\n\treturn idMap.get(intervalId) ?? intervalId;\n}\n\n/**\n * Create revertibles for adding an interval\n * @alpha\n */\nexport function appendAddIntervalToRevertibles(\n\tinterval: SequenceInterval,\n\trevertibles: SharedStringRevertible[],\n) {\n\trevertibles.push({\n\t\tevent: IntervalOpType.ADD,\n\t\tinterval,\n\t});\n\n\treturn revertibles;\n}\n\n/**\n * Create revertibles for deleting an interval\n * @alpha\n */\nexport function appendDeleteIntervalToRevertibles(\n\tstring: SharedString,\n\tinterval: SequenceInterval,\n\trevertibles: SharedStringRevertible[],\n) {\n\tconst startSeg = interval.start.getSegment() as SharedStringSegment;\n\tconst startType =\n\t\tstartSeg.removedSeq !== undefined\n\t\t\t? ReferenceType.SlideOnRemove | ReferenceType.RangeBegin\n\t\t\t: ReferenceType.StayOnRemove | ReferenceType.RangeBegin;\n\tconst endSeg = interval.end.getSegment() as SharedStringSegment;\n\tconst endType =\n\t\tendSeg.removedSeq !== undefined\n\t\t\t? ReferenceType.SlideOnRemove | ReferenceType.RangeEnd\n\t\t\t: ReferenceType.StayOnRemove | ReferenceType.RangeEnd;\n\tconst startRef = string.createLocalReferencePosition(\n\t\tstartSeg,\n\t\tinterval.start.getOffset(),\n\t\tstartType,\n\t\tundefined,\n\t\tinterval.start.slidingPreference,\n\t);\n\tconst endRef = string.createLocalReferencePosition(\n\t\tendSeg,\n\t\tinterval.end.getOffset(),\n\t\tendType,\n\t\tundefined,\n\t\tinterval.end.slidingPreference,\n\t);\n\tconst revertible = {\n\t\tevent: IntervalOpType.DELETE,\n\t\tinterval,\n\t\tstart: startRef,\n\t\tend: endRef,\n\t};\n\trevertible.start.addProperties({ revertible });\n\trevertible.end.addProperties({ revertible });\n\trevertibles.push(revertible);\n\n\treturn revertibles;\n}\n\n/**\n * Create revertibles for moving endpoints of an interval\n * @alpha\n */\nexport function appendChangeIntervalToRevertibles(\n\tstring: SharedString,\n\tnewInterval: SequenceInterval,\n\tpreviousInterval: SequenceInterval,\n\trevertibles: SharedStringRevertible[],\n) {\n\tconst startSeg = previousInterval.start.getSegment() as SharedStringSegment;\n\t// This logic is needed because the ReferenceType StayOnRemove cannot be used\n\t// on removed segments. This works for revertibles because the old position of the\n\t// interval within the removed segment is handled by the remove range revertible.\n\tconst startType =\n\t\tstartSeg.removedSeq !== undefined\n\t\t\t? ReferenceType.SlideOnRemove | ReferenceType.RangeBegin\n\t\t\t: ReferenceType.StayOnRemove | ReferenceType.RangeBegin;\n\tconst endSeg = previousInterval.end.getSegment() as SharedStringSegment;\n\tconst endType =\n\t\tendSeg.removedSeq !== undefined\n\t\t\t? ReferenceType.SlideOnRemove | ReferenceType.RangeEnd\n\t\t\t: ReferenceType.StayOnRemove | ReferenceType.RangeEnd;\n\tconst prevStartRef = string.createLocalReferencePosition(\n\t\tstartSeg,\n\t\tpreviousInterval.start.getOffset(),\n\t\tstartType,\n\t\tundefined,\n\t\tpreviousInterval.start.slidingPreference,\n\t);\n\tconst prevEndRef = string.createLocalReferencePosition(\n\t\tendSeg,\n\t\tpreviousInterval.end.getOffset(),\n\t\tendType,\n\t\tundefined,\n\t\tpreviousInterval.end.slidingPreference,\n\t);\n\tconst revertible = {\n\t\tevent: IntervalOpType.CHANGE,\n\t\tinterval: newInterval,\n\t\tstart: prevStartRef,\n\t\tend: prevEndRef,\n\t};\n\trevertible.start.addProperties({ revertible });\n\trevertible.end.addProperties({ revertible });\n\trevertibles.push(revertible);\n\n\treturn revertibles;\n}\n\n/**\n * Create revertibles for changing properties of an interval\n * @alpha\n */\nexport function appendIntervalPropertyChangedToRevertibles(\n\tinterval: SequenceInterval,\n\tdeltas: PropertySet,\n\trevertibles: SharedStringRevertible[],\n) {\n\trevertibles.push({\n\t\tevent: IntervalOpType.PROPERTY_CHANGED,\n\t\tinterval,\n\t\tpropertyDeltas: deltas,\n\t});\n\n\treturn revertibles;\n}\n\nfunction addIfIntervalEndpoint(\n\tref: LocalReferencePosition,\n\tsegmentLengths: number,\n\tstartIntervals: { offset: number; interval: SequenceInterval }[],\n\tendIntervals: { offset: number; interval: SequenceInterval }[],\n) {\n\tif (refTypeIncludesFlag(ref.refType, ReferenceType.RangeBegin)) {\n\t\tconst interval = ref.properties?.interval;\n\t\tif (interval && interval instanceof SequenceInterval) {\n\t\t\tstartIntervals.push({ offset: segmentLengths + interval.start.getOffset(), interval });\n\t\t\treturn true;\n\t\t}\n\t} else if (refTypeIncludesFlag(ref.refType, ReferenceType.RangeEnd)) {\n\t\tconst interval = ref.properties?.interval;\n\t\tif (interval && interval instanceof SequenceInterval) {\n\t\t\tendIntervals.push({ offset: segmentLengths + interval.end.getOffset(), interval });\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\nfunction addIfRevertibleRef(\n\tref: LocalReferencePosition,\n\tsegmentLengths: number,\n\trevertibleRefs: {\n\t\trevertible: IntervalRevertible;\n\t\toffset: number;\n\t\tisStart: boolean;\n\t}[],\n) {\n\tconst revertible = ref.properties?.revertible;\n\tif (revertible) {\n\t\trevertibleRefs.push({\n\t\t\trevertible,\n\t\t\toffset: segmentLengths + ref.getOffset(),\n\t\t\tisStart: refTypeIncludesFlag(ref.refType, ReferenceType.RangeBegin),\n\t\t});\n\t}\n}\n\n/**\n * Create revertibles for SharedStringDeltas, handling indirectly modified intervals\n * (e.g. reverting remove of a range that contains an interval will move the interval back)\n *\n * Revertibles are new and require the option mergeTreeUseNewLengthCalculations to\n * be set as true on the underlying merge tree in order to function correctly.\n *\n * @alpha\n */\nexport function appendSharedStringDeltaToRevertibles(\n\tstring: SharedString,\n\tdelta: SequenceDeltaEvent,\n\trevertibles: SharedStringRevertible[],\n) {\n\tif (delta.ranges.length === 0) {\n\t\treturn;\n\t}\n\tif (delta.deltaOperation === MergeTreeDeltaType.REMOVE) {\n\t\tconst startIntervals: { offset: number; interval: SequenceInterval }[] = [];\n\t\tconst endIntervals: { offset: number; interval: SequenceInterval }[] = [];\n\t\tconst revertibleRefs: {\n\t\t\trevertible: IntervalRevertible;\n\t\t\toffset: number;\n\t\t\tisStart: boolean;\n\t\t}[] = [];\n\t\tlet segmentLengths = 0;\n\n\t\t// find interval endpoints in each segment\n\t\tfor (const deltaRange of delta.ranges) {\n\t\t\tconst refs = deltaRange.segment.localRefs;\n\t\t\tif (refs !== undefined && deltaRange.position !== -1) {\n\t\t\t\tfor (const ref of refs) {\n\t\t\t\t\taddIfIntervalEndpoint(ref, segmentLengths, startIntervals, endIntervals);\n\t\t\t\t\taddIfRevertibleRef(ref, segmentLengths, revertibleRefs);\n\t\t\t\t}\n\t\t\t}\n\t\t\tsegmentLengths += deltaRange.segment.cachedLength;\n\t\t}\n\n\t\tif (startIntervals.length > 0 || endIntervals.length > 0 || revertibleRefs.length > 0) {\n\t\t\tconst removeRevertibles: MergeTreeDeltaRevertible[] = [];\n\t\t\tappendToMergeTreeDeltaRevertibles(delta.deltaArgs, removeRevertibles);\n\t\t\tassert(\n\t\t\t\tremoveRevertibles.length === 1,\n\t\t\t\t0x6c4 /* Remove revertible should be a single delta */,\n\t\t\t);\n\n\t\t\tconst revertible: TypedRevertible<typeof IntervalOpType.POSITION_REMOVE> = {\n\t\t\t\tevent: IntervalOpType.POSITION_REMOVE,\n\t\t\t\tintervals: [],\n\t\t\t\trevertibleRefs,\n\t\t\t\tmergeTreeRevertible: removeRevertibles[0],\n\t\t\t};\n\n\t\t\t// add an interval for each startInterval, accounting for any corresponding endIntervals\n\t\t\tstartIntervals.forEach(({ interval, offset }) => {\n\t\t\t\t// find any corresponding end for this interval\n\t\t\t\tconst endIntervalIndex = endIntervals.findIndex((end) => {\n\t\t\t\t\treturn end.interval === interval;\n\t\t\t\t});\n\t\t\t\tlet endOffset: number | undefined;\n\t\t\t\tif (endIntervalIndex !== -1) {\n\t\t\t\t\tendOffset = endIntervals[endIntervalIndex].offset;\n\t\t\t\t\tendIntervals.splice(endIntervalIndex, 1);\n\t\t\t\t}\n\n\t\t\t\trevertible.intervals.push({\n\t\t\t\t\tintervalId: interval.getIntervalId(),\n\t\t\t\t\tlabel: interval.properties.referenceRangeLabels[0],\n\t\t\t\t\tstartOffset: offset,\n\t\t\t\t\tendOffset,\n\t\t\t\t});\n\t\t\t});\n\n\t\t\t// add any remaining endIntervals that aren't matched with a startInterval\n\t\t\tendIntervals.forEach(({ interval, offset }) => {\n\t\t\t\trevertible.intervals.push({\n\t\t\t\t\tintervalId: interval.getIntervalId(),\n\t\t\t\t\tlabel: interval.properties.referenceRangeLabels[0],\n\t\t\t\t\tendOffset: offset,\n\t\t\t\t});\n\t\t\t});\n\n\t\t\trevertibles.push(revertible);\n\t\t\treturn;\n\t\t}\n\t}\n\n\t// Handle any merge tree delta that is not REMOVE or is REMOVE with no interval endpoints\n\tconst mergeTreeRevertibles: MergeTreeDeltaRevertible[] = [];\n\t// Allow merging MergeTreeDeltaRevertible with previous\n\tif (revertibles.length > 0 && isMergeTreeDeltaRevertible(revertibles[revertibles.length - 1])) {\n\t\tmergeTreeRevertibles.push(revertibles.pop() as MergeTreeDeltaRevertible);\n\t}\n\tappendToMergeTreeDeltaRevertibles(delta.deltaArgs, mergeTreeRevertibles);\n\trevertibles.push(...mergeTreeRevertibles);\n}\n\n/**\n * Clean up resources held by revertibles that are no longer needed.\n * @alpha\n */\nexport function discardSharedStringRevertibles(\n\tsharedString: SharedString,\n\trevertibles: SharedStringRevertible[],\n) {\n\trevertibles.forEach((r) => {\n\t\tif (isMergeTreeDeltaRevertible(r)) {\n\t\t\tdiscardMergeTreeDeltaRevertible([r]);\n\t\t} else if (r.event === IntervalOpType.CHANGE || r.event === IntervalOpType.DELETE) {\n\t\t\tsharedString.removeLocalReferencePosition(r.start);\n\t\t\tsharedString.removeLocalReferencePosition(r.end);\n\t\t}\n\t});\n}\n\nfunction getSlidePosition(string: SharedString, lref: LocalReferencePosition, pos: number): number {\n\tconst slide = getSlideToSegoff(\n\t\t{ segment: lref.getSegment(), offset: undefined },\n\t\tlref.slidingPreference,\n\t);\n\treturn slide?.segment !== undefined &&\n\t\tslide.offset !== undefined &&\n\t\tstring.getPosition(slide.segment) !== -1 &&\n\t\t(pos < 0 || pos >= string.getLength())\n\t\t? string.getPosition(slide.segment) + slide.offset\n\t\t: pos;\n}\n\nfunction isValidRange(start: number, end: number, string: SharedString) {\n\treturn (\n\t\tstart >= 0 &&\n\t\tstart < string.getLength() &&\n\t\tend >= 0 &&\n\t\tend < string.getLength() &&\n\t\tstart <= end\n\t);\n}\n\nfunction revertLocalAdd(\n\tstring: SharedString,\n\trevertible: TypedRevertible<typeof IntervalOpType.ADD>,\n) {\n\tconst id = getUpdatedIdFromInterval(revertible.interval);\n\tconst label = revertible.interval.properties.referenceRangeLabels[0];\n\tstring.getIntervalCollection(label).removeIntervalById(id);\n}\n\nfunction revertLocalDelete(\n\tstring: SharedString,\n\trevertible: TypedRevertible<typeof IntervalOpType.DELETE>,\n) {\n\tconst label = revertible.interval.properties.referenceRangeLabels[0];\n\tconst collection = string.getIntervalCollection(label);\n\tconst start = string.localReferencePositionToPosition(revertible.start);\n\tconst startSlidePos = getSlidePosition(string, revertible.start, start);\n\tconst end = string.localReferencePositionToPosition(revertible.end);\n\tconst endSlidePos = getSlidePosition(string, revertible.end, end);\n\tconst type = revertible.interval.intervalType;\n\t// reusing the id causes eventual consistency bugs, so it is removed here and recreated in add\n\tconst { intervalId, ...props } = revertible.interval.properties;\n\tif (!isValidRange(startSlidePos, endSlidePos, string)) return;\n\tconst int = collection.add(startSlidePos, endSlidePos, type, props);\n\n\tidMap.forEach((newId, oldId) => {\n\t\tif (intervalId === newId) {\n\t\t\tidMap.set(oldId, getUpdatedIdFromInterval(int));\n\t\t}\n\t});\n\tidMap.set(intervalId, int.getIntervalId());\n\n\tstring.removeLocalReferencePosition(revertible.start);\n\tstring.removeLocalReferencePosition(revertible.end);\n}\n\nfunction revertLocalChange(\n\tstring: SharedString,\n\trevertible: TypedRevertible<typeof IntervalOpType.CHANGE>,\n) {\n\tconst label = revertible.interval.properties.referenceRangeLabels[0];\n\tconst collection = string.getIntervalCollection(label);\n\tconst id = getUpdatedIdFromInterval(revertible.interval);\n\tconst start = string.localReferencePositionToPosition(revertible.start);\n\tconst startSlidePos = getSlidePosition(string, revertible.start, start);\n\tconst end = string.localReferencePositionToPosition(revertible.end);\n\tconst endSlidePos = getSlidePosition(string, revertible.end, end);\n\tif (!isValidRange(startSlidePos, endSlidePos, string)) return;\n\tcollection.change(id, startSlidePos, endSlidePos);\n\n\tstring.removeLocalReferencePosition(revertible.start);\n\tstring.removeLocalReferencePosition(revertible.end);\n}\n\nfunction revertLocalPropertyChanged(\n\tstring: SharedString,\n\trevertible: TypedRevertible<typeof IntervalOpType.PROPERTY_CHANGED>,\n) {\n\tconst label = revertible.interval.properties.referenceRangeLabels[0];\n\tconst id = getUpdatedIdFromInterval(revertible.interval);\n\tconst newProps = revertible.propertyDeltas;\n\tstring.getIntervalCollection(label).changeProperties(id, newProps);\n}\n\nfunction newPosition(offset: number | undefined, restoredRanges: SortedRangeSet) {\n\tif (offset === undefined) {\n\t\treturn undefined;\n\t}\n\n\tlet offsetFromSegment = offset;\n\tfor (const rangeInfo of restoredRanges.items) {\n\t\tif (offsetFromSegment < rangeInfo.length) {\n\t\t\t// find the segment inside the range\n\t\t\tfor (const range of rangeInfo.ranges) {\n\t\t\t\tif (range.segment.cachedLength > offsetFromSegment) {\n\t\t\t\t\treturn { segment: range.segment, offset: offsetFromSegment };\n\t\t\t\t}\n\t\t\t\toffsetFromSegment -= range.segment.cachedLength;\n\t\t\t}\n\t\t}\n\t\toffsetFromSegment -= rangeInfo.length;\n\t}\n\n\treturn undefined;\n}\n\nfunction newEndpointPosition(\n\toffset: number | undefined,\n\trestoredRanges: SortedRangeSet,\n\tsharedString: SharedString,\n) {\n\tconst pos = newPosition(offset, restoredRanges);\n\treturn pos === undefined ? undefined : sharedString.getPosition(pos.segment) + pos.offset;\n}\n\ninterface RangeInfo {\n\tranges: readonly Readonly<ISequenceDeltaRange<MergeTreeDeltaOperationType>>[];\n\tlength: number;\n}\n\nclass SortedRangeSet extends SortedSet<RangeInfo, string> {\n\tprotected getKey(item: RangeInfo): string {\n\t\treturn item.ranges[0].segment.ordinal;\n\t}\n}\n\nfunction revertLocalSequenceRemove(\n\tsharedString: SharedString,\n\trevertible: TypedRevertible<typeof IntervalOpType.POSITION_REMOVE>,\n) {\n\tconst restoredRanges = new SortedRangeSet();\n\tconst saveSegments = (event: SequenceDeltaEvent) => {\n\t\tif (event.ranges.length > 0) {\n\t\t\tlet length = 0;\n\t\t\tevent.ranges.forEach((range) => {\n\t\t\t\tlength += range.segment.cachedLength;\n\t\t\t});\n\t\t\trestoredRanges.addOrUpdate({ ranges: event.ranges, length });\n\t\t}\n\t};\n\tsharedString.on(\"sequenceDelta\", saveSegments);\n\trevertMergeTreeDeltaRevertibles(sharedString, [revertible.mergeTreeRevertible]);\n\tsharedString.off(\"sequenceDelta\", saveSegments);\n\n\trevertible.intervals.forEach((intervalInfo) => {\n\t\tconst intervalCollection = sharedString.getIntervalCollection(intervalInfo.label);\n\t\tconst intervalId = getUpdatedId(intervalInfo.intervalId);\n\t\tconst interval = intervalCollection.getIntervalById(intervalId);\n\t\tif (interval !== undefined) {\n\t\t\tconst newStart = newEndpointPosition(\n\t\t\t\tintervalInfo.startOffset,\n\t\t\t\trestoredRanges,\n\t\t\t\tsharedString,\n\t\t\t);\n\t\t\tconst newEnd = newEndpointPosition(\n\t\t\t\tintervalInfo.endOffset,\n\t\t\t\trestoredRanges,\n\t\t\t\tsharedString,\n\t\t\t);\n\t\t\tif (newStart !== undefined || newEnd !== undefined) {\n\t\t\t\tintervalCollection.change(intervalId, newStart, newEnd);\n\t\t\t}\n\t\t}\n\t});\n\n\t// fix up the local references used by delete and change revertibles\n\trevertible.revertibleRefs.forEach((revertibleRef) => {\n\t\tassert(\n\t\t\trevertibleRef.revertible.event === IntervalOpType.CHANGE ||\n\t\t\t\trevertibleRef.revertible.event === IntervalOpType.DELETE,\n\t\t\t0x6c5 /* revertible is not delete or change */,\n\t\t);\n\t\tconst pos = newPosition(revertibleRef.offset, restoredRanges);\n\t\tif (pos !== undefined) {\n\t\t\tif (revertibleRef.isStart) {\n\t\t\t\tsharedString.removeLocalReferencePosition(revertibleRef.revertible.start);\n\t\t\t\tconst newRef = sharedString.createLocalReferencePosition(\n\t\t\t\t\tpos.segment as SharedStringSegment,\n\t\t\t\t\tpos.offset,\n\t\t\t\t\tReferenceType.StayOnRemove | ReferenceType.RangeBegin,\n\t\t\t\t\t{ revertible: revertibleRef.revertible },\n\t\t\t\t);\n\t\t\t\trevertibleRef.revertible.start = newRef;\n\t\t\t} else {\n\t\t\t\tsharedString.removeLocalReferencePosition(revertibleRef.revertible.end);\n\t\t\t\tconst newRef = sharedString.createLocalReferencePosition(\n\t\t\t\t\tpos.segment as SharedStringSegment,\n\t\t\t\t\tpos.offset,\n\t\t\t\t\tReferenceType.StayOnRemove | ReferenceType.RangeEnd,\n\t\t\t\t\t{ revertible: revertibleRef.revertible },\n\t\t\t\t);\n\t\t\t\trevertibleRef.revertible.end = newRef;\n\t\t\t}\n\t\t}\n\t});\n}\n\n/**\n * Invoke revertibles to reverse prior edits\n *\n * Revertibles are new and require the option mergeTreeUseNewLengthCalculations to\n * be set as true on the underlying merge tree in order to function correctly.\n *\n * @alpha\n */\nexport function revertSharedStringRevertibles(\n\tsharedString: SharedString,\n\trevertibles: SharedStringRevertible[],\n) {\n\twhile (revertibles.length > 0) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst r = revertibles.pop()!;\n\t\tif (\"event\" in r) {\n\t\t\tconst event = r.event;\n\t\t\tswitch (event) {\n\t\t\t\tcase IntervalOpType.ADD:\n\t\t\t\t\trevertLocalAdd(sharedString, r);\n\t\t\t\t\tbreak;\n\t\t\t\tcase IntervalOpType.DELETE:\n\t\t\t\t\trevertLocalDelete(sharedString, r);\n\t\t\t\t\tbreak;\n\t\t\t\tcase IntervalOpType.CHANGE:\n\t\t\t\t\trevertLocalChange(sharedString, r);\n\t\t\t\t\tbreak;\n\t\t\t\tcase IntervalOpType.PROPERTY_CHANGED:\n\t\t\t\t\trevertLocalPropertyChanged(sharedString, r);\n\t\t\t\t\tbreak;\n\t\t\t\tcase IntervalOpType.POSITION_REMOVE:\n\t\t\t\t\trevertLocalSequenceRemove(sharedString, r);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tunreachableCase(event);\n\t\t\t}\n\t\t} else {\n\t\t\trevertMergeTreeDeltaRevertibles(sharedString, [r]);\n\t\t}\n\t}\n}\n"]}
package/lib/sequence.d.ts CHANGED
@@ -5,11 +5,11 @@
5
5
  import { Deferred } from "@fluidframework/common-utils";
6
6
  import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
7
7
  import { IChannelAttributes, IFluidDataStoreRuntime, IChannelStorageService } from "@fluidframework/datastore-definitions";
8
- import { Client, ICombiningOp, IJSONSegment, IMergeTreeGroupMsg, IMergeTreeOp, IMergeTreeRemoveMsg, IRelativePosition, ISegment, ISegmentAction, LocalReferencePosition, PropertySet, RangeStackMap, ReferencePosition, ReferenceType, MergeTreeRevertibleDriver } from "@fluidframework/merge-tree";
8
+ import { Client, ICombiningOp, IJSONSegment, IMergeTreeGroupMsg, IMergeTreeOp, IMergeTreeRemoveMsg, IRelativePosition, ISegment, ISegmentAction, LocalReferencePosition, PropertySet, RangeStackMap, ReferencePosition, ReferenceType, MergeTreeRevertibleDriver, SlidingPreference } from "@fluidframework/merge-tree";
9
9
  import { IFluidSerializer, SharedObject, ISharedObjectEvents, SummarySerializer } from "@fluidframework/shared-object-base";
10
10
  import { IEventThisPlaceHolder } from "@fluidframework/common-definitions";
11
11
  import { ISummaryTreeWithStats, ITelemetryContext } from "@fluidframework/runtime-definitions";
12
- import { IntervalCollection, SequenceInterval } from "./intervalCollection";
12
+ import { IIntervalCollection, SequenceInterval } from "./intervalCollection";
13
13
  import { SequenceDeltaEvent, SequenceMaintenanceEvent } from "./sequenceDeltaEvent";
14
14
  import { ISharedIntervalCollection } from "./sharedIntervalCollection";
15
15
  /**
@@ -113,7 +113,7 @@ export declare abstract class SharedSegmentSequence<T extends ISegment> extends
113
113
  * @param refType - ReferenceType for the created local reference
114
114
  * @param properties - PropertySet to place on the created local reference
115
115
  */
116
- createLocalReferencePosition(segment: T, offset: number, refType: ReferenceType, properties: PropertySet | undefined): LocalReferencePosition;
116
+ createLocalReferencePosition(segment: T, offset: number, refType: ReferenceType, properties: PropertySet | undefined, slidingPreference?: SlidingPreference): LocalReferencePosition;
117
117
  /**
118
118
  * Resolves a `ReferencePosition` into a character position using this client's perspective.
119
119
  */
@@ -180,7 +180,7 @@ export declare abstract class SharedSegmentSequence<T extends ISegment> extends
180
180
  * Retrieves the interval collection keyed on `label`. If no such interval collection exists,
181
181
  * creates one.
182
182
  */
183
- getIntervalCollection(label: string): IntervalCollection<SequenceInterval>;
183
+ getIntervalCollection(label: string): IIntervalCollection<SequenceInterval>;
184
184
  /**
185
185
  * @returns An iterable object that enumerates the IntervalCollection labels.
186
186
  *
@@ -1 +1 @@
1
- {"version":3,"file":"sequence.d.ts","sourceRoot":"","sources":["../src/sequence.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,QAAQ,EAA0B,MAAM,8BAA8B,CAAC;AAEhF,OAAO,EAAE,yBAAyB,EAAe,MAAM,sCAAsC,CAAC;AAC9F,OAAO,EACN,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACN,MAAM,EAKN,YAAY,EACZ,YAAY,EAGZ,kBAAkB,EAClB,YAAY,EACZ,mBAAmB,EACn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iB;IAQzD;;;;;;;;OAQG;IACH,SAAS,CAAC,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ;IAiBpE;;OAEG;IACH,SAAS,CAAC,SAAS;IAKnB;;OAEG;IACH,SAAS,CAAC,YAAY;IAEtB;;OAEG;IACH,SAAS,CAAC,YAAY,CAAC,OAAO,EAAE,GAAG,EAAE,eAAe,EAAE,OAAO;IAgB7D;;OAEG;cACa,QAAQ,CAAC,OAAO,EAAE,sBAAsB;IA4DxD;;OAEG;IACH,SAAS,CAAC,WAAW,CACpB,OAAO,EAAE,yBAAyB,EAClC,KAAK,EAAE,OAAO,EACd,eAAe,EAAE,OAAO;IA0BzB;;OAEG;IACH,SAAS,CAAC,SAAS;IAQnB;;OAEG;IACH,SAAS,CAAC,mBAAmB;IAK7B;;OAEG;IACH,SAAS,CAAC,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO;IAI/C,OAAO,CAAC,kBAAkB;IAsB1B,OAAO,CAAC,mBAAmB;IAyC3B,OAAO,CAAC,+BAA+B;IAYvC,OAAO,CAAC,YAAY;IA6BpB,OAAO,CAAC,6BAA6B;CAuBrC"}
package/lib/sequence.js CHANGED
@@ -37,7 +37,7 @@ export class SharedSegmentSequence extends SharedObject {
37
37
  this.client.on("maintenance", (args, opArgs) => {
38
38
  this.emit("maintenance", new SequenceMaintenanceEvent(opArgs, args, this.client), this);
39
39
  });
40
- this.intervalCollections = new DefaultMap(this.serializer, this.handle, (op, localOpMetadata) => this.submitLocalMessage(op, localOpMetadata), new SequenceIntervalCollectionValueType());
40
+ this.intervalCollections = new DefaultMap(this.serializer, this.handle, (op, localOpMetadata) => this.submitLocalMessage(op, localOpMetadata), new SequenceIntervalCollectionValueType(), dataStoreRuntime.options);
41
41
  }
42
42
  get loaded() {
43
43
  return this.loadedDeferred.promise;
@@ -146,8 +146,8 @@ export class SharedSegmentSequence extends SharedObject {
146
146
  * @param refType - ReferenceType for the created local reference
147
147
  * @param properties - PropertySet to place on the created local reference
148
148
  */
149
- createLocalReferencePosition(segment, offset, refType, properties) {
150
- return this.client.createLocalReferencePosition(segment, offset, refType, properties);
149
+ createLocalReferencePosition(segment, offset, refType, properties, slidingPreference) {
150
+ return this.client.createLocalReferencePosition(segment, offset, refType, properties, slidingPreference);
151
151
  }
152
152
  /**
153
153
  * Resolves a `ReferencePosition` into a character position using this client's perspective.