@fluidframework/sequence 2.0.0-dev.5.2.0.169897 → 2.0.0-dev.6.4.0.191258

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 (231) hide show
  1. package/CHANGELOG.md +142 -0
  2. package/README.md +4 -3
  3. package/dist/defaultMap.d.ts +1 -1
  4. package/dist/defaultMap.d.ts.map +1 -1
  5. package/dist/defaultMap.js +9 -10
  6. package/dist/defaultMap.js.map +1 -1
  7. package/dist/defaultMapInterfaces.d.ts +1 -1
  8. package/dist/defaultMapInterfaces.d.ts.map +1 -1
  9. package/dist/defaultMapInterfaces.js.map +1 -1
  10. package/dist/index.d.ts +3 -2
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +15 -9
  13. package/dist/index.js.map +1 -1
  14. package/dist/intervalCollection.d.ts +14 -437
  15. package/dist/intervalCollection.d.ts.map +1 -1
  16. package/dist/intervalCollection.js +96 -916
  17. package/dist/intervalCollection.js.map +1 -1
  18. package/dist/intervalIndex/endpointInRangeIndex.d.ts +20 -0
  19. package/dist/intervalIndex/endpointInRangeIndex.d.ts.map +1 -0
  20. package/dist/intervalIndex/endpointInRangeIndex.js +60 -0
  21. package/dist/intervalIndex/endpointInRangeIndex.js.map +1 -0
  22. package/dist/intervalIndex/endpointIndex.d.ts +21 -0
  23. package/dist/intervalIndex/endpointIndex.d.ts.map +1 -0
  24. package/dist/intervalIndex/endpointIndex.js +42 -0
  25. package/dist/intervalIndex/endpointIndex.js.map +1 -0
  26. package/dist/intervalIndex/idIntervalIndex.d.ts +12 -0
  27. package/dist/intervalIndex/idIntervalIndex.d.ts.map +1 -0
  28. package/dist/intervalIndex/idIntervalIndex.js +41 -0
  29. package/dist/intervalIndex/idIntervalIndex.js.map +1 -0
  30. package/dist/intervalIndex/index.d.ts +13 -0
  31. package/dist/intervalIndex/index.d.ts.map +1 -0
  32. package/dist/intervalIndex/index.js +20 -0
  33. package/dist/intervalIndex/index.js.map +1 -0
  34. package/dist/intervalIndex/intervalIndex.d.ts +29 -0
  35. package/dist/intervalIndex/intervalIndex.d.ts.map +1 -0
  36. package/dist/intervalIndex/intervalIndex.js +7 -0
  37. package/dist/intervalIndex/intervalIndex.js.map +1 -0
  38. package/dist/intervalIndex/intervalIndexUtils.d.ts +17 -0
  39. package/dist/intervalIndex/intervalIndexUtils.d.ts.map +1 -0
  40. package/dist/intervalIndex/intervalIndexUtils.js +22 -0
  41. package/dist/intervalIndex/intervalIndexUtils.js.map +1 -0
  42. package/dist/intervalIndex/overlappingIntervalsIndex.d.ts +33 -0
  43. package/dist/intervalIndex/overlappingIntervalsIndex.d.ts.map +1 -0
  44. package/dist/intervalIndex/overlappingIntervalsIndex.js +103 -0
  45. package/dist/intervalIndex/overlappingIntervalsIndex.js.map +1 -0
  46. package/dist/intervalIndex/overlappingSequenceIntervalsIndex.d.ts +8 -0
  47. package/dist/intervalIndex/overlappingSequenceIntervalsIndex.d.ts.map +1 -0
  48. package/dist/intervalIndex/overlappingSequenceIntervalsIndex.js +33 -0
  49. package/dist/intervalIndex/overlappingSequenceIntervalsIndex.js.map +1 -0
  50. package/dist/intervalIndex/sequenceIntervalIndexes.d.ts +33 -0
  51. package/dist/intervalIndex/sequenceIntervalIndexes.d.ts.map +1 -0
  52. package/dist/intervalIndex/sequenceIntervalIndexes.js +7 -0
  53. package/dist/intervalIndex/sequenceIntervalIndexes.js.map +1 -0
  54. package/dist/intervalIndex/startpointInRangeIndex.d.ts +20 -0
  55. package/dist/intervalIndex/startpointInRangeIndex.d.ts.map +1 -0
  56. package/dist/intervalIndex/startpointInRangeIndex.js +62 -0
  57. package/dist/intervalIndex/startpointInRangeIndex.js.map +1 -0
  58. package/dist/intervalTree.d.ts +2 -56
  59. package/dist/intervalTree.d.ts.map +1 -1
  60. package/dist/intervalTree.js +2 -11
  61. package/dist/intervalTree.js.map +1 -1
  62. package/dist/intervals/index.d.ts +8 -0
  63. package/dist/intervals/index.d.ts.map +1 -0
  64. package/dist/intervals/index.js +23 -0
  65. package/dist/intervals/index.js.map +1 -0
  66. package/dist/intervals/interval.d.ts +88 -0
  67. package/dist/intervals/interval.d.ts.map +1 -0
  68. package/dist/intervals/interval.js +180 -0
  69. package/dist/intervals/interval.js.map +1 -0
  70. package/dist/intervals/intervalUtils.d.ts +200 -0
  71. package/dist/intervals/intervalUtils.d.ts.map +1 -0
  72. package/dist/intervals/intervalUtils.js +79 -0
  73. package/dist/intervals/intervalUtils.js.map +1 -0
  74. package/dist/intervals/sequenceInterval.d.ts +132 -0
  75. package/dist/intervals/sequenceInterval.d.ts.map +1 -0
  76. package/dist/intervals/sequenceInterval.js +313 -0
  77. package/dist/intervals/sequenceInterval.js.map +1 -0
  78. package/dist/packageVersion.d.ts +1 -1
  79. package/dist/packageVersion.js +1 -1
  80. package/dist/packageVersion.js.map +1 -1
  81. package/dist/revertibles.d.ts +1 -1
  82. package/dist/revertibles.d.ts.map +1 -1
  83. package/dist/revertibles.js +85 -52
  84. package/dist/revertibles.js.map +1 -1
  85. package/dist/sequence.d.ts +33 -4
  86. package/dist/sequence.d.ts.map +1 -1
  87. package/dist/sequence.js +91 -47
  88. package/dist/sequence.js.map +1 -1
  89. package/dist/sequenceDeltaEvent.d.ts +8 -3
  90. package/dist/sequenceDeltaEvent.d.ts.map +1 -1
  91. package/dist/sequenceDeltaEvent.js +3 -4
  92. package/dist/sequenceDeltaEvent.js.map +1 -1
  93. package/dist/sharedIntervalCollection.d.ts +2 -1
  94. package/dist/sharedIntervalCollection.d.ts.map +1 -1
  95. package/dist/sharedIntervalCollection.js +2 -2
  96. package/dist/sharedIntervalCollection.js.map +1 -1
  97. package/dist/sharedSequence.d.ts +9 -0
  98. package/dist/sharedSequence.d.ts.map +1 -1
  99. package/dist/sharedSequence.js +9 -6
  100. package/dist/sharedSequence.js.map +1 -1
  101. package/dist/sharedString.d.ts.map +1 -1
  102. package/dist/sharedString.js +9 -29
  103. package/dist/sharedString.js.map +1 -1
  104. package/lib/defaultMap.d.ts +1 -1
  105. package/lib/defaultMap.d.ts.map +1 -1
  106. package/lib/defaultMap.js +5 -6
  107. package/lib/defaultMap.js.map +1 -1
  108. package/lib/defaultMapInterfaces.d.ts +1 -1
  109. package/lib/defaultMapInterfaces.d.ts.map +1 -1
  110. package/lib/defaultMapInterfaces.js.map +1 -1
  111. package/lib/index.d.ts +3 -2
  112. package/lib/index.d.ts.map +1 -1
  113. package/lib/index.js +3 -1
  114. package/lib/index.js.map +1 -1
  115. package/lib/intervalCollection.d.ts +14 -437
  116. package/lib/intervalCollection.d.ts.map +1 -1
  117. package/lib/intervalCollection.js +64 -877
  118. package/lib/intervalCollection.js.map +1 -1
  119. package/lib/intervalIndex/endpointInRangeIndex.d.ts +20 -0
  120. package/lib/intervalIndex/endpointInRangeIndex.d.ts.map +1 -0
  121. package/lib/intervalIndex/endpointInRangeIndex.js +56 -0
  122. package/lib/intervalIndex/endpointInRangeIndex.js.map +1 -0
  123. package/lib/intervalIndex/endpointIndex.d.ts +21 -0
  124. package/lib/intervalIndex/endpointIndex.d.ts.map +1 -0
  125. package/lib/intervalIndex/endpointIndex.js +38 -0
  126. package/lib/intervalIndex/endpointIndex.js.map +1 -0
  127. package/lib/intervalIndex/idIntervalIndex.d.ts +12 -0
  128. package/lib/intervalIndex/idIntervalIndex.d.ts.map +1 -0
  129. package/lib/intervalIndex/idIntervalIndex.js +37 -0
  130. package/lib/intervalIndex/idIntervalIndex.js.map +1 -0
  131. package/lib/intervalIndex/index.d.ts +13 -0
  132. package/lib/intervalIndex/index.d.ts.map +1 -0
  133. package/lib/intervalIndex/index.js +11 -0
  134. package/lib/intervalIndex/index.js.map +1 -0
  135. package/lib/intervalIndex/intervalIndex.d.ts +29 -0
  136. package/lib/intervalIndex/intervalIndex.d.ts.map +1 -0
  137. package/lib/intervalIndex/intervalIndex.js +6 -0
  138. package/lib/intervalIndex/intervalIndex.js.map +1 -0
  139. package/lib/intervalIndex/intervalIndexUtils.d.ts +17 -0
  140. package/lib/intervalIndex/intervalIndexUtils.d.ts.map +1 -0
  141. package/lib/intervalIndex/intervalIndexUtils.js +18 -0
  142. package/lib/intervalIndex/intervalIndexUtils.js.map +1 -0
  143. package/lib/intervalIndex/overlappingIntervalsIndex.d.ts +33 -0
  144. package/lib/intervalIndex/overlappingIntervalsIndex.d.ts.map +1 -0
  145. package/lib/intervalIndex/overlappingIntervalsIndex.js +98 -0
  146. package/lib/intervalIndex/overlappingIntervalsIndex.js.map +1 -0
  147. package/lib/intervalIndex/overlappingSequenceIntervalsIndex.d.ts +8 -0
  148. package/lib/intervalIndex/overlappingSequenceIntervalsIndex.d.ts.map +1 -0
  149. package/lib/intervalIndex/overlappingSequenceIntervalsIndex.js +29 -0
  150. package/lib/intervalIndex/overlappingSequenceIntervalsIndex.js.map +1 -0
  151. package/lib/intervalIndex/sequenceIntervalIndexes.d.ts +33 -0
  152. package/lib/intervalIndex/sequenceIntervalIndexes.d.ts.map +1 -0
  153. package/lib/intervalIndex/sequenceIntervalIndexes.js +6 -0
  154. package/lib/intervalIndex/sequenceIntervalIndexes.js.map +1 -0
  155. package/lib/intervalIndex/startpointInRangeIndex.d.ts +20 -0
  156. package/lib/intervalIndex/startpointInRangeIndex.d.ts.map +1 -0
  157. package/lib/intervalIndex/startpointInRangeIndex.js +58 -0
  158. package/lib/intervalIndex/startpointInRangeIndex.js.map +1 -0
  159. package/lib/intervalTree.d.ts +2 -56
  160. package/lib/intervalTree.d.ts.map +1 -1
  161. package/lib/intervalTree.js +2 -11
  162. package/lib/intervalTree.js.map +1 -1
  163. package/lib/intervals/index.d.ts +8 -0
  164. package/lib/intervals/index.d.ts.map +1 -0
  165. package/lib/intervals/index.js +8 -0
  166. package/lib/intervals/index.js.map +1 -0
  167. package/lib/intervals/interval.d.ts +88 -0
  168. package/lib/intervals/interval.d.ts.map +1 -0
  169. package/lib/intervals/interval.js +175 -0
  170. package/lib/intervals/interval.js.map +1 -0
  171. package/lib/intervals/intervalUtils.d.ts +200 -0
  172. package/lib/intervals/intervalUtils.d.ts.map +1 -0
  173. package/lib/intervals/intervalUtils.js +74 -0
  174. package/lib/intervals/intervalUtils.js.map +1 -0
  175. package/lib/intervals/sequenceInterval.d.ts +132 -0
  176. package/lib/intervals/sequenceInterval.d.ts.map +1 -0
  177. package/lib/intervals/sequenceInterval.js +305 -0
  178. package/lib/intervals/sequenceInterval.js.map +1 -0
  179. package/lib/packageVersion.d.ts +1 -1
  180. package/lib/packageVersion.js +1 -1
  181. package/lib/packageVersion.js.map +1 -1
  182. package/lib/revertibles.d.ts +1 -1
  183. package/lib/revertibles.d.ts.map +1 -1
  184. package/lib/revertibles.js +69 -36
  185. package/lib/revertibles.js.map +1 -1
  186. package/lib/sequence.d.ts +33 -4
  187. package/lib/sequence.d.ts.map +1 -1
  188. package/lib/sequence.js +86 -41
  189. package/lib/sequence.js.map +1 -1
  190. package/lib/sequenceDeltaEvent.d.ts +8 -3
  191. package/lib/sequenceDeltaEvent.d.ts.map +1 -1
  192. package/lib/sequenceDeltaEvent.js +2 -3
  193. package/lib/sequenceDeltaEvent.js.map +1 -1
  194. package/lib/sharedIntervalCollection.d.ts +2 -1
  195. package/lib/sharedIntervalCollection.d.ts.map +1 -1
  196. package/lib/sharedIntervalCollection.js +1 -1
  197. package/lib/sharedIntervalCollection.js.map +1 -1
  198. package/lib/sharedSequence.d.ts +9 -0
  199. package/lib/sharedSequence.d.ts.map +1 -1
  200. package/lib/sharedSequence.js +8 -5
  201. package/lib/sharedSequence.js.map +1 -1
  202. package/lib/sharedString.d.ts.map +1 -1
  203. package/lib/sharedString.js +9 -29
  204. package/lib/sharedString.js.map +1 -1
  205. package/package.json +31 -34
  206. package/src/defaultMap.ts +2 -1
  207. package/src/defaultMapInterfaces.ts +1 -1
  208. package/src/index.ts +21 -9
  209. package/src/intervalCollection.ts +118 -1403
  210. package/src/intervalIndex/endpointInRangeIndex.ts +104 -0
  211. package/src/intervalIndex/endpointIndex.ts +78 -0
  212. package/src/intervalIndex/idIntervalIndex.ts +58 -0
  213. package/src/intervalIndex/index.ts +16 -0
  214. package/src/intervalIndex/intervalIndex.ts +31 -0
  215. package/src/intervalIndex/intervalIndexUtils.ts +27 -0
  216. package/src/intervalIndex/overlappingIntervalsIndex.ts +162 -0
  217. package/src/intervalIndex/overlappingSequenceIntervalsIndex.ts +71 -0
  218. package/src/intervalIndex/sequenceIntervalIndexes.ts +32 -0
  219. package/src/intervalIndex/startpointInRangeIndex.ts +109 -0
  220. package/src/intervalTree.ts +3 -75
  221. package/src/intervals/index.ts +25 -0
  222. package/src/intervals/interval.ts +230 -0
  223. package/src/intervals/intervalUtils.ts +256 -0
  224. package/src/intervals/sequenceInterval.ts +494 -0
  225. package/src/packageVersion.ts +1 -1
  226. package/src/revertibles.ts +81 -16
  227. package/src/sequence.ts +100 -35
  228. package/src/sequenceDeltaEvent.ts +12 -4
  229. package/src/sharedIntervalCollection.ts +2 -3
  230. package/src/sharedSequence.ts +11 -5
  231. package/src/sharedString.ts +8 -25
@@ -0,0 +1,305 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ /* eslint-disable no-bitwise */
6
+ import { PropertiesManager, ReferenceType, compareReferencePositions, createDetachedLocalReferencePosition, createMap, getSlideToSegoff, maxReferencePosition, minReferencePosition, refTypeIncludesFlag, reservedRangeLabelsKey, } from "@fluidframework/merge-tree";
7
+ import { assert } from "@fluidframework/core-utils";
8
+ import { UsageError } from "@fluidframework/telemetry-utils";
9
+ import { IntervalStickiness, IntervalType, endReferenceSlidingPreference, startReferenceSlidingPreference, } from "./intervalUtils";
10
+ const reservedIntervalIdKey = "intervalId";
11
+ /**
12
+ * Interval implementation whose ends are associated with positions in a mutatable sequence.
13
+ * As such, when content is inserted into the middle of the interval, the interval expands to
14
+ * include that content.
15
+ *
16
+ * @remarks The endpoint's position should be treated exclusively to get reasonable behavior--i.e.
17
+ * an interval referring to "hello" in "hello world" should have a start position of 0 and an end
18
+ * position of 5.
19
+ *
20
+ * To see why, consider what happens if "llo wor" is removed from the string to make "held".
21
+ * The interval's startpoint remains on the "h" (it isn't altered), but the interval's endpoint
22
+ * slides forward to the next unremoved position, which is the "l" in "held".
23
+ * Users would generally expect the interval to now refer to "he" (as it is the subset of content
24
+ * remaining after the removal), hence the "l" should be excluded.
25
+ * If the interval endpoint was treated inclusively, the interval would now refer to "hel", which
26
+ * is undesirable.
27
+ *
28
+ * Since the end of an interval is treated exclusively but cannot be greater than or equal to the
29
+ * length of the associated sequence, application models which leverage interval collections should
30
+ * consider inserting a marker at the end of the sequence to represent the end of the content.
31
+ */
32
+ export class SequenceInterval {
33
+ constructor(client,
34
+ /**
35
+ * Start endpoint of this interval.
36
+ * @remarks This endpoint can be resolved into a character position using the SharedString it's a part of.
37
+ */
38
+ start,
39
+ /**
40
+ * End endpoint of this interval.
41
+ * @remarks This endpoint can be resolved into a character position using the SharedString it's a part of.
42
+ */
43
+ end, intervalType, props, stickiness = IntervalStickiness.END) {
44
+ this.client = client;
45
+ this.start = start;
46
+ this.end = end;
47
+ this.intervalType = intervalType;
48
+ this.stickiness = stickiness;
49
+ this.propertyManager = new PropertiesManager();
50
+ this.properties = {};
51
+ if (props) {
52
+ this.addProperties(props);
53
+ }
54
+ }
55
+ /**
56
+ * Subscribes to position change events on this interval if there are no current listeners.
57
+ * @internal
58
+ */
59
+ addPositionChangeListeners(beforePositionChange, afterPositionChange) {
60
+ var _a, _b;
61
+ if (this.callbacks === undefined) {
62
+ this.callbacks = {
63
+ beforePositionChange,
64
+ afterPositionChange,
65
+ };
66
+ const startCbs = ((_a = this.start).callbacks ?? (_a.callbacks = {}));
67
+ const endCbs = ((_b = this.end).callbacks ?? (_b.callbacks = {}));
68
+ startCbs.beforeSlide = endCbs.beforeSlide = beforePositionChange;
69
+ startCbs.afterSlide = endCbs.afterSlide = afterPositionChange;
70
+ }
71
+ }
72
+ /**
73
+ * Removes the currently subscribed position change listeners.
74
+ * @internal
75
+ */
76
+ removePositionChangeListeners() {
77
+ if (this.callbacks) {
78
+ this.callbacks = undefined;
79
+ this.start.callbacks = undefined;
80
+ this.end.callbacks = undefined;
81
+ }
82
+ }
83
+ /**
84
+ * {@inheritDoc ISerializableInterval.serialize}
85
+ * @internal
86
+ */
87
+ serialize() {
88
+ const startPosition = this.client.localReferencePositionToPosition(this.start);
89
+ const endPosition = this.client.localReferencePositionToPosition(this.end);
90
+ const serializedInterval = {
91
+ end: endPosition,
92
+ intervalType: this.intervalType,
93
+ sequenceNumber: this.client.getCurrentSeq(),
94
+ start: startPosition,
95
+ };
96
+ if (this.properties) {
97
+ serializedInterval.properties = this.properties;
98
+ }
99
+ if (this.stickiness !== IntervalStickiness.END) {
100
+ serializedInterval.stickiness = this.stickiness;
101
+ }
102
+ return serializedInterval;
103
+ }
104
+ /**
105
+ * {@inheritDoc IInterval.clone}
106
+ */
107
+ clone() {
108
+ return new SequenceInterval(this.client, this.start, this.end, this.intervalType, this.properties, this.stickiness);
109
+ }
110
+ /**
111
+ * {@inheritDoc IInterval.compare}
112
+ */
113
+ compare(b) {
114
+ const startResult = this.compareStart(b);
115
+ if (startResult === 0) {
116
+ const endResult = this.compareEnd(b);
117
+ if (endResult === 0) {
118
+ const thisId = this.getIntervalId();
119
+ if (thisId) {
120
+ const bId = b.getIntervalId();
121
+ if (bId) {
122
+ return thisId > bId ? 1 : thisId < bId ? -1 : 0;
123
+ }
124
+ return 0;
125
+ }
126
+ return 0;
127
+ }
128
+ else {
129
+ return endResult;
130
+ }
131
+ }
132
+ else {
133
+ return startResult;
134
+ }
135
+ }
136
+ /**
137
+ * {@inheritDoc IInterval.compareStart}
138
+ */
139
+ compareStart(b) {
140
+ return compareReferencePositions(this.start, b.start);
141
+ }
142
+ /**
143
+ * {@inheritDoc IInterval.compareEnd}
144
+ */
145
+ compareEnd(b) {
146
+ return compareReferencePositions(this.end, b.end);
147
+ }
148
+ /**
149
+ * {@inheritDoc IInterval.overlaps}
150
+ */
151
+ overlaps(b) {
152
+ const result = compareReferencePositions(this.start, b.end) <= 0 &&
153
+ compareReferencePositions(this.end, b.start) >= 0;
154
+ return result;
155
+ }
156
+ /**
157
+ * {@inheritDoc ISerializableInterval.getIntervalId}
158
+ */
159
+ getIntervalId() {
160
+ const id = this.properties?.[reservedIntervalIdKey];
161
+ assert(id !== undefined, 0x5e2 /* interval ID should not be undefined */);
162
+ return `${id}`;
163
+ }
164
+ /**
165
+ * {@inheritDoc IInterval.union}
166
+ * @internal
167
+ */
168
+ union(b) {
169
+ return new SequenceInterval(this.client, minReferencePosition(this.start, b.start), maxReferencePosition(this.end, b.end), this.intervalType);
170
+ }
171
+ /**
172
+ * {@inheritDoc ISerializableInterval.addProperties}
173
+ * @internal
174
+ */
175
+ addProperties(newProps, collab = false, seq, op) {
176
+ this.initializeProperties();
177
+ return this.propertyManager.addProperties(this.properties, newProps, op, seq, collab);
178
+ }
179
+ /**
180
+ * @returns whether this interval overlaps two numerical positions.
181
+ */
182
+ overlapsPos(bstart, bend) {
183
+ const startPos = this.client.localReferencePositionToPosition(this.start);
184
+ const endPos = this.client.localReferencePositionToPosition(this.end);
185
+ return endPos > bstart && startPos < bend;
186
+ }
187
+ /**
188
+ * {@inheritDoc IInterval.modify}
189
+ * @internal
190
+ */
191
+ modify(label, start, end, op, localSeq, stickiness = IntervalStickiness.END) {
192
+ const getRefType = (baseType) => {
193
+ let refType = baseType;
194
+ if (op === undefined) {
195
+ refType &= ~ReferenceType.SlideOnRemove;
196
+ refType |= ReferenceType.StayOnRemove;
197
+ }
198
+ return refType;
199
+ };
200
+ let startRef = this.start;
201
+ if (start !== undefined) {
202
+ startRef = createPositionReference(this.client, start, getRefType(this.start.refType), op, undefined, localSeq, startReferenceSlidingPreference(stickiness));
203
+ if (this.start.properties) {
204
+ startRef.addProperties(this.start.properties);
205
+ }
206
+ }
207
+ let endRef = this.end;
208
+ if (end !== undefined) {
209
+ endRef = createPositionReference(this.client, end, getRefType(this.end.refType), op, undefined, localSeq, endReferenceSlidingPreference(stickiness));
210
+ if (this.end.properties) {
211
+ endRef.addProperties(this.end.properties);
212
+ }
213
+ }
214
+ const newInterval = new SequenceInterval(this.client, startRef, endRef, this.intervalType);
215
+ if (this.properties) {
216
+ newInterval.initializeProperties();
217
+ this.propertyManager.copyTo(this.properties, newInterval.properties, newInterval.propertyManager);
218
+ }
219
+ return newInterval;
220
+ }
221
+ initializeProperties() {
222
+ if (!this.propertyManager) {
223
+ this.propertyManager = new PropertiesManager();
224
+ }
225
+ if (!this.properties) {
226
+ this.properties = createMap();
227
+ }
228
+ }
229
+ }
230
+ export function createPositionReferenceFromSegoff(client, segoff, refType, op, localSeq, fromSnapshot, slidingPreference) {
231
+ if (segoff.segment) {
232
+ const ref = client.createLocalReferencePosition(segoff.segment, segoff.offset, refType, undefined, slidingPreference);
233
+ return ref;
234
+ }
235
+ // Creating references on detached segments is allowed for:
236
+ // - Transient segments
237
+ // - References coming from a remote client (location may have been concurrently removed)
238
+ // - References being rebased to a new sequence number
239
+ // (segment they originally referred to may have been removed with no suitable replacement)
240
+ if (!op &&
241
+ !localSeq &&
242
+ !fromSnapshot &&
243
+ !refTypeIncludesFlag(refType, ReferenceType.Transient)) {
244
+ throw new UsageError("Non-transient references need segment");
245
+ }
246
+ return createDetachedLocalReferencePosition(refType);
247
+ }
248
+ function createPositionReference(client, pos, refType, op, fromSnapshot, localSeq, slidingPreference) {
249
+ let segoff;
250
+ if (op) {
251
+ assert((refType & ReferenceType.SlideOnRemove) !== 0, 0x2f5 /* op create references must be SlideOnRemove */);
252
+ segoff = client.getContainingSegment(pos, {
253
+ referenceSequenceNumber: op.referenceSequenceNumber,
254
+ clientId: op.clientId,
255
+ });
256
+ segoff = getSlideToSegoff(segoff);
257
+ }
258
+ else {
259
+ assert((refType & ReferenceType.SlideOnRemove) === 0 || !!fromSnapshot, 0x2f6 /* SlideOnRemove references must be op created */);
260
+ segoff = client.getContainingSegment(pos, undefined, localSeq);
261
+ }
262
+ return createPositionReferenceFromSegoff(client, segoff, refType, op, localSeq, fromSnapshot, slidingPreference);
263
+ }
264
+ export function createSequenceInterval(label, start, end, client, intervalType, op, fromSnapshot, stickiness = IntervalStickiness.END) {
265
+ let beginRefType = ReferenceType.RangeBegin;
266
+ let endRefType = ReferenceType.RangeEnd;
267
+ if (intervalType === IntervalType.Transient) {
268
+ beginRefType = ReferenceType.Transient;
269
+ endRefType = ReferenceType.Transient;
270
+ }
271
+ else {
272
+ if (intervalType === IntervalType.Nest) {
273
+ beginRefType = ReferenceType.NestBegin;
274
+ endRefType = ReferenceType.NestEnd;
275
+ }
276
+ // All non-transient interval references must eventually be SlideOnRemove
277
+ // To ensure eventual consistency, they must start as StayOnRemove when
278
+ // pending (created locally and creation op is not acked)
279
+ if (op || fromSnapshot) {
280
+ beginRefType |= ReferenceType.SlideOnRemove;
281
+ endRefType |= ReferenceType.SlideOnRemove;
282
+ }
283
+ else {
284
+ beginRefType |= ReferenceType.StayOnRemove;
285
+ endRefType |= ReferenceType.StayOnRemove;
286
+ }
287
+ }
288
+ const startLref = createPositionReference(client, start, beginRefType, op, fromSnapshot, undefined, startReferenceSlidingPreference(stickiness));
289
+ const endLref = createPositionReference(client, end, endRefType, op, fromSnapshot, undefined, endReferenceSlidingPreference(stickiness));
290
+ const rangeProp = {
291
+ [reservedRangeLabelsKey]: [label],
292
+ };
293
+ startLref.addProperties(rangeProp);
294
+ endLref.addProperties(rangeProp);
295
+ const ival = new SequenceInterval(client, startLref, endLref, intervalType, rangeProp, stickiness);
296
+ return ival;
297
+ }
298
+ export const compareSequenceIntervalEnds = (a, b) => compareReferencePositions(a.end, b.end);
299
+ export const compareSequenceIntervalStarts = (a, b) => compareReferencePositions(a.start, b.start);
300
+ export const sequenceIntervalHelpers = {
301
+ compareEnds: compareSequenceIntervalEnds,
302
+ compareStarts: compareSequenceIntervalStarts,
303
+ create: createSequenceInterval,
304
+ };
305
+ //# sourceMappingURL=sequenceInterval.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sequenceInter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C,CAAmB,EAAE,CAAmB,EAAU,EAAE,CACjG,yBAAyB,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;AAE7C,MAAM,CAAC,MAAM,uBAAuB,GAAuC;IAC1E,WAAW,EAAE,2BAA2B;IACxC,aAAa,EAAE,6BAA6B;IAC5C,MAAM,EAAE,sBAAsB;CAC9B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable no-bitwise */\n\nimport {\n\tClient,\n\tICombiningOp,\n\tISegment,\n\tLocalReferencePosition,\n\tPropertiesManager,\n\tPropertySet,\n\tReferenceType,\n\tSlidingPreference,\n\tcompareReferencePositions,\n\tcreateDetachedLocalReferencePosition,\n\tcreateMap,\n\tgetSlideToSegoff,\n\tmaxReferencePosition,\n\tminReferencePosition,\n\trefTypeIncludesFlag,\n\treservedRangeLabelsKey,\n} from \"@fluidframework/merge-tree\";\nimport { assert } from \"@fluidframework/core-utils\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport { UsageError } from \"@fluidframework/telemetry-utils\";\nimport {\n\tIIntervalHelpers,\n\tISerializableInterval,\n\tISerializedInterval,\n\tIntervalStickiness,\n\tIntervalType,\n\tendReferenceSlidingPreference,\n\tstartReferenceSlidingPreference,\n} from \"./intervalUtils\";\n\nconst reservedIntervalIdKey = \"intervalId\";\n\n/**\n * Interval implementation whose ends are associated with positions in a mutatable sequence.\n * As such, when content is inserted into the middle of the interval, the interval expands to\n * include that content.\n *\n * @remarks The endpoint's position should be treated exclusively to get reasonable behavior--i.e.\n * an interval referring to \"hello\" in \"hello world\" should have a start position of 0 and an end\n * position of 5.\n *\n * To see why, consider what happens if \"llo wor\" is removed from the string to make \"held\".\n * The interval's startpoint remains on the \"h\" (it isn't altered), but the interval's endpoint\n * slides forward to the next unremoved position, which is the \"l\" in \"held\".\n * Users would generally expect the interval to now refer to \"he\" (as it is the subset of content\n * remaining after the removal), hence the \"l\" should be excluded.\n * If the interval endpoint was treated inclusively, the interval would now refer to \"hel\", which\n * is undesirable.\n *\n * Since the end of an interval is treated exclusively but cannot be greater than or equal to the\n * length of the associated sequence, application models which leverage interval collections should\n * consider inserting a marker at the end of the sequence to represent the end of the content.\n */\nexport class SequenceInterval implements ISerializableInterval {\n\t/**\n\t * {@inheritDoc ISerializableInterval.properties}\n\t */\n\tpublic properties: PropertySet;\n\t/**\n\t * {@inheritDoc ISerializableInterval.propertyManager}\n\t * @internal\n\t */\n\tpublic propertyManager: PropertiesManager;\n\n\tconstructor(\n\t\tprivate readonly client: Client,\n\t\t/**\n\t\t * Start endpoint of this interval.\n\t\t * @remarks This endpoint can be resolved into a character position using the SharedString it's a part of.\n\t\t */\n\t\tpublic start: LocalReferencePosition,\n\t\t/**\n\t\t * End endpoint of this interval.\n\t\t * @remarks This endpoint can be resolved into a character position using the SharedString it's a part of.\n\t\t */\n\t\tpublic end: LocalReferencePosition,\n\t\tpublic intervalType: IntervalType,\n\t\tprops?: PropertySet,\n\t\tpublic readonly stickiness: IntervalStickiness = IntervalStickiness.END,\n\t) {\n\t\tthis.propertyManager = new PropertiesManager();\n\t\tthis.properties = {};\n\n\t\tif (props) {\n\t\t\tthis.addProperties(props);\n\t\t}\n\t}\n\n\tprivate callbacks?: Record<\"beforePositionChange\" | \"afterPositionChange\", () => void>;\n\n\t/**\n\t * Subscribes to position change events on this interval if there are no current listeners.\n\t * @internal\n\t */\n\tpublic addPositionChangeListeners(\n\t\tbeforePositionChange: () => void,\n\t\tafterPositionChange: () => void,\n\t): void {\n\t\tif (this.callbacks === undefined) {\n\t\t\tthis.callbacks = {\n\t\t\t\tbeforePositionChange,\n\t\t\t\tafterPositionChange,\n\t\t\t};\n\n\t\t\tconst startCbs = (this.start.callbacks ??= {});\n\t\t\tconst endCbs = (this.end.callbacks ??= {});\n\t\t\tstartCbs.beforeSlide = endCbs.beforeSlide = beforePositionChange;\n\t\t\tstartCbs.afterSlide = endCbs.afterSlide = afterPositionChange;\n\t\t}\n\t}\n\n\t/**\n\t * Removes the currently subscribed position change listeners.\n\t * @internal\n\t */\n\tpublic removePositionChangeListeners(): void {\n\t\tif (this.callbacks) {\n\t\t\tthis.callbacks = undefined;\n\t\t\tthis.start.callbacks = undefined;\n\t\t\tthis.end.callbacks = undefined;\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc ISerializableInterval.serialize}\n\t * @internal\n\t */\n\tpublic serialize(): ISerializedInterval {\n\t\tconst startPosition = this.client.localReferencePositionToPosition(this.start);\n\t\tconst endPosition = this.client.localReferencePositionToPosition(this.end);\n\t\tconst serializedInterval: ISerializedInterval = {\n\t\t\tend: endPosition,\n\t\t\tintervalType: this.intervalType,\n\t\t\tsequenceNumber: this.client.getCurrentSeq(),\n\t\t\tstart: startPosition,\n\t\t};\n\n\t\tif (this.properties) {\n\t\t\tserializedInterval.properties = this.properties;\n\t\t}\n\t\tif (this.stickiness !== IntervalStickiness.END) {\n\t\t\tserializedInterval.stickiness = this.stickiness;\n\t\t}\n\n\t\treturn serializedInterval;\n\t}\n\n\t/**\n\t * {@inheritDoc IInterval.clone}\n\t */\n\tpublic clone() {\n\t\treturn new SequenceInterval(\n\t\t\tthis.client,\n\t\t\tthis.start,\n\t\t\tthis.end,\n\t\t\tthis.intervalType,\n\t\t\tthis.properties,\n\t\t\tthis.stickiness,\n\t\t);\n\t}\n\n\t/**\n\t * {@inheritDoc IInterval.compare}\n\t */\n\tpublic compare(b: SequenceInterval) {\n\t\tconst startResult = this.compareStart(b);\n\t\tif (startResult === 0) {\n\t\t\tconst endResult = this.compareEnd(b);\n\t\t\tif (endResult === 0) {\n\t\t\t\tconst thisId = this.getIntervalId();\n\t\t\t\tif (thisId) {\n\t\t\t\t\tconst bId = b.getIntervalId();\n\t\t\t\t\tif (bId) {\n\t\t\t\t\t\treturn thisId > bId ? 1 : thisId < bId ? -1 : 0;\n\t\t\t\t\t}\n\t\t\t\t\treturn 0;\n\t\t\t\t}\n\t\t\t\treturn 0;\n\t\t\t} else {\n\t\t\t\treturn endResult;\n\t\t\t}\n\t\t} else {\n\t\t\treturn startResult;\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritDoc IInterval.compareStart}\n\t */\n\tpublic compareStart(b: SequenceInterval) {\n\t\treturn compareReferencePositions(this.start, b.start);\n\t}\n\n\t/**\n\t * {@inheritDoc IInterval.compareEnd}\n\t */\n\tpublic compareEnd(b: SequenceInterval) {\n\t\treturn compareReferencePositions(this.end, b.end);\n\t}\n\n\t/**\n\t * {@inheritDoc IInterval.overlaps}\n\t */\n\tpublic overlaps(b: SequenceInterval) {\n\t\tconst result =\n\t\t\tcompareReferencePositions(this.start, b.end) <= 0 &&\n\t\t\tcompareReferencePositions(this.end, b.start) >= 0;\n\t\treturn result;\n\t}\n\n\t/**\n\t * {@inheritDoc ISerializableInterval.getIntervalId}\n\t */\n\tpublic getIntervalId(): string {\n\t\tconst id = this.properties?.[reservedIntervalIdKey];\n\t\tassert(id !== undefined, 0x5e2 /* interval ID should not be undefined */);\n\t\treturn `${id}`;\n\t}\n\n\t/**\n\t * {@inheritDoc IInterval.union}\n\t * @internal\n\t */\n\tpublic union(b: SequenceInterval) {\n\t\treturn new SequenceInterval(\n\t\t\tthis.client,\n\t\t\tminReferencePosition(this.start, b.start),\n\t\t\tmaxReferencePosition(this.end, b.end),\n\t\t\tthis.intervalType,\n\t\t);\n\t}\n\n\t/**\n\t * {@inheritDoc ISerializableInterval.addProperties}\n\t * @internal\n\t */\n\tpublic addProperties(\n\t\tnewProps: PropertySet,\n\t\tcollab: boolean = false,\n\t\tseq?: number,\n\t\top?: ICombiningOp,\n\t): PropertySet | undefined {\n\t\tthis.initializeProperties();\n\t\treturn this.propertyManager.addProperties(this.properties, newProps, op, seq, collab);\n\t}\n\n\t/**\n\t * @returns whether this interval overlaps two numerical positions.\n\t */\n\tpublic overlapsPos(bstart: number, bend: number) {\n\t\tconst startPos = this.client.localReferencePositionToPosition(this.start);\n\t\tconst endPos = this.client.localReferencePositionToPosition(this.end);\n\t\treturn endPos > bstart && startPos < bend;\n\t}\n\n\t/**\n\t * {@inheritDoc IInterval.modify}\n\t * @internal\n\t */\n\tpublic modify(\n\t\tlabel: string,\n\t\tstart: number,\n\t\tend: number,\n\t\top?: ISequencedDocumentMessage,\n\t\tlocalSeq?: number,\n\t\tstickiness: IntervalStickiness = IntervalStickiness.END,\n\t) {\n\t\tconst getRefType = (baseType: ReferenceType): ReferenceType => {\n\t\t\tlet refType = baseType;\n\t\t\tif (op === undefined) {\n\t\t\t\trefType &= ~ReferenceType.SlideOnRemove;\n\t\t\t\trefType |= ReferenceType.StayOnRemove;\n\t\t\t}\n\t\t\treturn refType;\n\t\t};\n\n\t\tlet startRef = this.start;\n\t\tif (start !== undefined) {\n\t\t\tstartRef = createPositionReference(\n\t\t\t\tthis.client,\n\t\t\t\tstart,\n\t\t\t\tgetRefType(this.start.refType),\n\t\t\t\top,\n\t\t\t\tundefined,\n\t\t\t\tlocalSeq,\n\t\t\t\tstartReferenceSlidingPreference(stickiness),\n\t\t\t);\n\t\t\tif (this.start.properties) {\n\t\t\t\tstartRef.addProperties(this.start.properties);\n\t\t\t}\n\t\t}\n\n\t\tlet endRef = this.end;\n\t\tif (end !== undefined) {\n\t\t\tendRef = createPositionReference(\n\t\t\t\tthis.client,\n\t\t\t\tend,\n\t\t\t\tgetRefType(this.end.refType),\n\t\t\t\top,\n\t\t\t\tundefined,\n\t\t\t\tlocalSeq,\n\t\t\t\tendReferenceSlidingPreference(stickiness),\n\t\t\t);\n\t\t\tif (this.end.properties) {\n\t\t\t\tendRef.addProperties(this.end.properties);\n\t\t\t}\n\t\t}\n\n\t\tconst newInterval = new SequenceInterval(this.client, startRef, endRef, this.intervalType);\n\t\tif (this.properties) {\n\t\t\tnewInterval.initializeProperties();\n\t\t\tthis.propertyManager.copyTo(\n\t\t\t\tthis.properties,\n\t\t\t\tnewInterval.properties,\n\t\t\t\tnewInterval.propertyManager,\n\t\t\t);\n\t\t}\n\t\treturn newInterval;\n\t}\n\n\tprivate initializeProperties(): void {\n\t\tif (!this.propertyManager) {\n\t\t\tthis.propertyManager = new PropertiesManager();\n\t\t}\n\t\tif (!this.properties) {\n\t\t\tthis.properties = createMap<any>();\n\t\t}\n\t}\n}\n\nexport function createPositionReferenceFromSegoff(\n\tclient: Client,\n\tsegoff: { segment: ISegment | undefined; offset: number | undefined },\n\trefType: ReferenceType,\n\top?: ISequencedDocumentMessage,\n\tlocalSeq?: number,\n\tfromSnapshot?: boolean,\n\tslidingPreference?: SlidingPreference,\n): LocalReferencePosition {\n\tif (segoff.segment) {\n\t\tconst ref = client.createLocalReferencePosition(\n\t\t\tsegoff.segment,\n\t\t\tsegoff.offset,\n\t\t\trefType,\n\t\t\tundefined,\n\t\t\tslidingPreference,\n\t\t);\n\t\treturn ref;\n\t}\n\n\t// Creating references on detached segments is allowed for:\n\t// - Transient segments\n\t// - References coming from a remote client (location may have been concurrently removed)\n\t// - References being rebased to a new sequence number\n\t// (segment they originally referred to may have been removed with no suitable replacement)\n\tif (\n\t\t!op &&\n\t\t!localSeq &&\n\t\t!fromSnapshot &&\n\t\t!refTypeIncludesFlag(refType, ReferenceType.Transient)\n\t) {\n\t\tthrow new UsageError(\"Non-transient references need segment\");\n\t}\n\n\treturn createDetachedLocalReferencePosition(refType);\n}\n\nfunction createPositionReference(\n\tclient: Client,\n\tpos: number,\n\trefType: ReferenceType,\n\top?: ISequencedDocumentMessage,\n\tfromSnapshot?: boolean,\n\tlocalSeq?: number,\n\tslidingPreference?: SlidingPreference,\n): LocalReferencePosition {\n\tlet segoff;\n\tif (op) {\n\t\tassert(\n\t\t\t(refType & ReferenceType.SlideOnRemove) !== 0,\n\t\t\t0x2f5 /* op create references must be SlideOnRemove */,\n\t\t);\n\t\tsegoff = client.getContainingSegment(pos, {\n\t\t\treferenceSequenceNumber: op.referenceSequenceNumber,\n\t\t\tclientId: op.clientId,\n\t\t});\n\t\tsegoff = getSlideToSegoff(segoff);\n\t} else {\n\t\tassert(\n\t\t\t(refType & ReferenceType.SlideOnRemove) === 0 || !!fromSnapshot,\n\t\t\t0x2f6 /* SlideOnRemove references must be op created */,\n\t\t);\n\t\tsegoff = client.getContainingSegment(pos, undefined, localSeq);\n\t}\n\n\treturn createPositionReferenceFromSegoff(\n\t\tclient,\n\t\tsegoff,\n\t\trefType,\n\t\top,\n\t\tlocalSeq,\n\t\tfromSnapshot,\n\t\tslidingPreference,\n\t);\n}\n\nexport function createSequenceInterval(\n\tlabel: string,\n\tstart: number,\n\tend: number,\n\tclient: Client,\n\tintervalType: IntervalType,\n\top?: ISequencedDocumentMessage,\n\tfromSnapshot?: boolean,\n\tstickiness: IntervalStickiness = IntervalStickiness.END,\n): SequenceInterval {\n\tlet beginRefType = ReferenceType.RangeBegin;\n\tlet endRefType = ReferenceType.RangeEnd;\n\tif (intervalType === IntervalType.Transient) {\n\t\tbeginRefType = ReferenceType.Transient;\n\t\tendRefType = ReferenceType.Transient;\n\t} else {\n\t\tif (intervalType === IntervalType.Nest) {\n\t\t\tbeginRefType = ReferenceType.NestBegin;\n\t\t\tendRefType = ReferenceType.NestEnd;\n\t\t}\n\t\t// All non-transient interval references must eventually be SlideOnRemove\n\t\t// To ensure eventual consistency, they must start as StayOnRemove when\n\t\t// pending (created locally and creation op is not acked)\n\t\tif (op || fromSnapshot) {\n\t\t\tbeginRefType |= ReferenceType.SlideOnRemove;\n\t\t\tendRefType |= ReferenceType.SlideOnRemove;\n\t\t} else {\n\t\t\tbeginRefType |= ReferenceType.StayOnRemove;\n\t\t\tendRefType |= ReferenceType.StayOnRemove;\n\t\t}\n\t}\n\n\tconst startLref = createPositionReference(\n\t\tclient,\n\t\tstart,\n\t\tbeginRefType,\n\t\top,\n\t\tfromSnapshot,\n\t\tundefined,\n\t\tstartReferenceSlidingPreference(stickiness),\n\t);\n\n\tconst endLref = createPositionReference(\n\t\tclient,\n\t\tend,\n\t\tendRefType,\n\t\top,\n\t\tfromSnapshot,\n\t\tundefined,\n\t\tendReferenceSlidingPreference(stickiness),\n\t);\n\n\tconst rangeProp = {\n\t\t[reservedRangeLabelsKey]: [label],\n\t};\n\tstartLref.addProperties(rangeProp);\n\tendLref.addProperties(rangeProp);\n\n\tconst ival = new SequenceInterval(\n\t\tclient,\n\t\tstartLref,\n\t\tendLref,\n\t\tintervalType,\n\t\trangeProp,\n\t\tstickiness,\n\t);\n\treturn ival;\n}\n\nexport const compareSequenceIntervalEnds = (a: SequenceInterval, b: SequenceInterval): number =>\n\tcompareReferencePositions(a.end, b.end);\n\nexport const compareSequenceIntervalStarts = (a: SequenceInterval, b: SequenceInterval): number =>\n\tcompareReferencePositions(a.start, b.start);\n\nexport const sequenceIntervalHelpers: IIntervalHelpers<SequenceInterval> = {\n\tcompareEnds: compareSequenceIntervalEnds,\n\tcompareStarts: compareSequenceIntervalStarts,\n\tcreate: createSequenceInterval,\n};\n"]}
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export declare const pkgName = "@fluidframework/sequence";
8
- export declare const pkgVersion = "2.0.0-dev.5.2.0.169897";
8
+ export declare const pkgVersion = "2.0.0-dev.6.4.0.191258";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export const pkgName = "@fluidframework/sequence";
8
- export const pkgVersion = "2.0.0-dev.5.2.0.169897";
8
+ export const pkgVersion = "2.0.0-dev.6.4.0.191258";
9
9
  //# sourceMappingURL=packageVersion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,0BAA0B,CAAC;AAClD,MAAM,CAAC,MAAM,UAAU,GAAG,wBAAwB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/sequence\";\nexport const pkgVersion = \"2.0.0-dev.5.2.0.169897\";\n"]}
1
+ {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,0BAA0B,CAAC;AAClD,MAAM,CAAC,MAAM,UAAU,GAAG,wBAAwB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/sequence\";\nexport const pkgVersion = \"2.0.0-dev.6.4.0.191258\";\n"]}
@@ -3,7 +3,7 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import { LocalReferencePosition, MergeTreeDeltaRevertible, PropertySet } from "@fluidframework/merge-tree";
6
- import { IntervalOpType, SequenceInterval } from "./intervalCollection";
6
+ import { IntervalOpType, SequenceInterval } from "./intervals";
7
7
  import { SharedString } from "./sharedString";
8
8
  import { SequenceDeltaEvent } from "./sequenceDeltaEvent";
9
9
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"revertibles.d.ts","sourceRoot":"","sources":["../src/revertibles.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAIN,sBAAsB,EAEtB,wBAAwB,EAExB,WAAW,EAKX,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,YAAY,EAAuB,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAuB,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE/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ED;;;GAGG;AACH,wBAAgB,iCAAiC,CAChD,MAAM,EAAE,YAAY,EACpB,WAAW,EAAE,gBAAgB,EAC7B,gBAAgB,EAAE,gBAAgB,EAClC,WAAW,EAAE,sBAAsB,EAAE,4BAwCrC;AAED;;;GAGG;AACH,wBAAgB,0CAA0C,CACzD,QAAQ,EAAE,gBAAgB,EAC1B,MAAM,EAAE,WAAW,EACnB,WAAW,EAAE,sBAAsB,EAAE,4BASrC;AA2CD;;;;;;;;GAQG;AACH,wBAAgB,oCAAoC,CACnD,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,kBAAkB,EACzB,WAAW,EAAE,sBAAsB,EAAE,QAoFrC;AAED;;;GAGG;AACH,wBAAgB,8BAA8B,CAC7C,YAAY,EAAE,YAAY,EAC1B,WAAW,EAAE,sBAAsB,EAAE,QAUrC;AAqND;;;;;;;GAOG;AACH,wBAAgB,6BAA6B,CAC5C,YAAY,EAAE,YAAY,EAC1B,WAAW,EAAE,sBAAsB,EAAE,QA8BrC"}
@@ -3,28 +3,16 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
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, } from "@fluidframework/merge-tree";
19
- import { IntervalOpType, SequenceInterval } from "./intervalCollection";
6
+ import { assert, unreachableCase } from "@fluidframework/core-utils";
7
+ import { appendToMergeTreeDeltaRevertibles, discardMergeTreeDeltaRevertible, isMergeTreeDeltaRevertible, MergeTreeDeltaType, ReferenceType, refTypeIncludesFlag, revertMergeTreeDeltaRevertibles, SortedSet, getSlideToSegoff, } from "@fluidframework/merge-tree";
8
+ import { IntervalOpType, SequenceInterval } from "./intervals";
20
9
  const idMap = new Map();
21
10
  function getUpdatedIdFromInterval(interval) {
22
11
  const maybeId = interval.getIntervalId();
23
12
  return getUpdatedId(maybeId);
24
13
  }
25
14
  function getUpdatedId(intervalId) {
26
- var _a;
27
- return (_a = idMap.get(intervalId)) !== null && _a !== void 0 ? _a : intervalId;
15
+ return idMap.get(intervalId) ?? intervalId;
28
16
  }
29
17
  /**
30
18
  * Create revertibles for adding an interval
@@ -43,9 +31,15 @@ export function appendAddIntervalToRevertibles(interval, revertibles) {
43
31
  */
44
32
  export function appendDeleteIntervalToRevertibles(string, interval, revertibles) {
45
33
  const startSeg = interval.start.getSegment();
34
+ const startType = startSeg.removedSeq !== undefined
35
+ ? ReferenceType.SlideOnRemove | ReferenceType.RangeBegin
36
+ : ReferenceType.StayOnRemove | ReferenceType.RangeBegin;
46
37
  const endSeg = interval.end.getSegment();
47
- const startRef = string.createLocalReferencePosition(startSeg, interval.start.getOffset(), ReferenceType.StayOnRemove | ReferenceType.RangeBegin, undefined);
48
- const endRef = string.createLocalReferencePosition(endSeg, interval.end.getOffset(), ReferenceType.StayOnRemove | ReferenceType.RangeEnd, undefined);
38
+ const endType = endSeg.removedSeq !== undefined
39
+ ? ReferenceType.SlideOnRemove | ReferenceType.RangeEnd
40
+ : ReferenceType.StayOnRemove | ReferenceType.RangeEnd;
41
+ const startRef = string.createLocalReferencePosition(startSeg, interval.start.getOffset(), startType, undefined, interval.start.slidingPreference);
42
+ const endRef = string.createLocalReferencePosition(endSeg, interval.end.getOffset(), endType, undefined, interval.end.slidingPreference);
49
43
  const revertible = {
50
44
  event: IntervalOpType.DELETE,
51
45
  interval,
@@ -63,9 +57,18 @@ export function appendDeleteIntervalToRevertibles(string, interval, revertibles)
63
57
  */
64
58
  export function appendChangeIntervalToRevertibles(string, newInterval, previousInterval, revertibles) {
65
59
  const startSeg = previousInterval.start.getSegment();
60
+ // This logic is needed because the ReferenceType StayOnRemove cannot be used
61
+ // on removed segments. This works for revertibles because the old position of the
62
+ // interval within the removed segment is handled by the remove range revertible.
63
+ const startType = startSeg.removedSeq !== undefined
64
+ ? ReferenceType.SlideOnRemove | ReferenceType.RangeBegin
65
+ : ReferenceType.StayOnRemove | ReferenceType.RangeBegin;
66
66
  const endSeg = previousInterval.end.getSegment();
67
- const prevStartRef = string.createLocalReferencePosition(startSeg, previousInterval.start.getOffset(), ReferenceType.StayOnRemove | ReferenceType.RangeBegin, undefined);
68
- const prevEndRef = string.createLocalReferencePosition(endSeg, previousInterval.end.getOffset(), ReferenceType.StayOnRemove | ReferenceType.RangeEnd, undefined);
67
+ const endType = endSeg.removedSeq !== undefined
68
+ ? ReferenceType.SlideOnRemove | ReferenceType.RangeEnd
69
+ : ReferenceType.StayOnRemove | ReferenceType.RangeEnd;
70
+ const prevStartRef = string.createLocalReferencePosition(startSeg, previousInterval.start.getOffset(), startType, undefined, previousInterval.start.slidingPreference);
71
+ const prevEndRef = string.createLocalReferencePosition(endSeg, previousInterval.end.getOffset(), endType, undefined, previousInterval.end.slidingPreference);
69
72
  const revertible = {
70
73
  event: IntervalOpType.CHANGE,
71
74
  interval: newInterval,
@@ -90,16 +93,15 @@ export function appendIntervalPropertyChangedToRevertibles(interval, deltas, rev
90
93
  return revertibles;
91
94
  }
92
95
  function addIfIntervalEndpoint(ref, segmentLengths, startIntervals, endIntervals) {
93
- var _a, _b;
94
96
  if (refTypeIncludesFlag(ref.refType, ReferenceType.RangeBegin)) {
95
- const interval = (_a = ref.properties) === null || _a === void 0 ? void 0 : _a.interval;
97
+ const interval = ref.properties?.interval;
96
98
  if (interval && interval instanceof SequenceInterval) {
97
99
  startIntervals.push({ offset: segmentLengths + interval.start.getOffset(), interval });
98
100
  return true;
99
101
  }
100
102
  }
101
103
  else if (refTypeIncludesFlag(ref.refType, ReferenceType.RangeEnd)) {
102
- const interval = (_b = ref.properties) === null || _b === void 0 ? void 0 : _b.interval;
104
+ const interval = ref.properties?.interval;
103
105
  if (interval && interval instanceof SequenceInterval) {
104
106
  endIntervals.push({ offset: segmentLengths + interval.end.getOffset(), interval });
105
107
  return true;
@@ -108,8 +110,7 @@ function addIfIntervalEndpoint(ref, segmentLengths, startIntervals, endIntervals
108
110
  return false;
109
111
  }
110
112
  function addIfRevertibleRef(ref, segmentLengths, revertibleRefs) {
111
- var _a;
112
- const revertible = (_a = ref.properties) === null || _a === void 0 ? void 0 : _a.revertible;
113
+ const revertible = ref.properties?.revertible;
113
114
  if (revertible) {
114
115
  revertibleRefs.push({
115
116
  revertible,
@@ -211,7 +212,22 @@ export function discardSharedStringRevertibles(sharedString, revertibles) {
211
212
  }
212
213
  });
213
214
  }
214
- // Uses of referenceRangeLabels will be removed once AB#4081 is completed.
215
+ function getSlidePosition(string, lref, pos) {
216
+ const slide = getSlideToSegoff({ segment: lref.getSegment(), offset: undefined }, lref.slidingPreference);
217
+ return slide?.segment !== undefined &&
218
+ slide.offset !== undefined &&
219
+ string.getPosition(slide.segment) !== -1 &&
220
+ (pos < 0 || pos >= string.getLength())
221
+ ? string.getPosition(slide.segment) + slide.offset
222
+ : pos;
223
+ }
224
+ function isValidRange(start, end, string) {
225
+ return (start >= 0 &&
226
+ start < string.getLength() &&
227
+ end >= 0 &&
228
+ end < string.getLength() &&
229
+ start <= end);
230
+ }
215
231
  function revertLocalAdd(string, revertible) {
216
232
  const id = getUpdatedIdFromInterval(revertible.interval);
217
233
  const label = revertible.interval.properties.referenceRangeLabels[0];
@@ -219,27 +235,37 @@ function revertLocalAdd(string, revertible) {
219
235
  }
220
236
  function revertLocalDelete(string, revertible) {
221
237
  const label = revertible.interval.properties.referenceRangeLabels[0];
238
+ const collection = string.getIntervalCollection(label);
222
239
  const start = string.localReferencePositionToPosition(revertible.start);
240
+ const startSlidePos = getSlidePosition(string, revertible.start, start);
223
241
  const end = string.localReferencePositionToPosition(revertible.end);
242
+ const endSlidePos = getSlidePosition(string, revertible.end, end);
224
243
  const type = revertible.interval.intervalType;
225
244
  // reusing the id causes eventual consistency bugs, so it is removed here and recreated in add
226
- const _a = revertible.interval.properties, { intervalId } = _a, props = __rest(_a, ["intervalId"]);
227
- const int = string.getIntervalCollection(label).add(start, end, type, props);
228
- idMap.forEach((newId, oldId) => {
229
- if (intervalId === newId) {
230
- idMap.set(oldId, getUpdatedIdFromInterval(int));
231
- }
232
- });
233
- idMap.set(intervalId, int.getIntervalId());
245
+ const { intervalId, ...props } = revertible.interval.properties;
246
+ if (isValidRange(startSlidePos, endSlidePos, string)) {
247
+ const int = collection.add(startSlidePos, endSlidePos, type, props);
248
+ idMap.forEach((newId, oldId) => {
249
+ if (intervalId === newId) {
250
+ idMap.set(oldId, getUpdatedIdFromInterval(int));
251
+ }
252
+ });
253
+ idMap.set(intervalId, int.getIntervalId());
254
+ }
234
255
  string.removeLocalReferencePosition(revertible.start);
235
256
  string.removeLocalReferencePosition(revertible.end);
236
257
  }
237
258
  function revertLocalChange(string, revertible) {
238
259
  const label = revertible.interval.properties.referenceRangeLabels[0];
260
+ const collection = string.getIntervalCollection(label);
239
261
  const id = getUpdatedIdFromInterval(revertible.interval);
240
262
  const start = string.localReferencePositionToPosition(revertible.start);
263
+ const startSlidePos = getSlidePosition(string, revertible.start, start);
241
264
  const end = string.localReferencePositionToPosition(revertible.end);
242
- string.getIntervalCollection(label).change(id, start, end);
265
+ const endSlidePos = getSlidePosition(string, revertible.end, end);
266
+ if (isValidRange(startSlidePos, endSlidePos, string)) {
267
+ collection.change(id, startSlidePos, endSlidePos);
268
+ }
243
269
  string.removeLocalReferencePosition(revertible.start);
244
270
  string.removeLocalReferencePosition(revertible.end);
245
271
  }
@@ -298,7 +324,14 @@ function revertLocalSequenceRemove(sharedString, revertible) {
298
324
  if (interval !== undefined) {
299
325
  const newStart = newEndpointPosition(intervalInfo.startOffset, restoredRanges, sharedString);
300
326
  const newEnd = newEndpointPosition(intervalInfo.endOffset, restoredRanges, sharedString);
301
- if (newStart !== undefined || newEnd !== undefined) {
327
+ // only move interval if start <= end
328
+ if ((newStart === undefined &&
329
+ newEnd !== undefined &&
330
+ sharedString.localReferencePositionToPosition(interval.start) <= newEnd) ||
331
+ (newEnd === undefined &&
332
+ newStart !== undefined &&
333
+ sharedString.localReferencePositionToPosition(interval.end) >= newStart) ||
334
+ (newStart !== undefined && newEnd !== undefined && newStart <= newEnd)) {
302
335
  intervalCollection.change(intervalId, newStart, newEnd);
303
336
  }
304
337
  }