@fluidframework/sequence 2.0.0-internal.7.0.0 → 2.0.0-internal.7.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +39 -0
- package/api-extractor.json +1 -1
- package/api-report/sequence.api.md +717 -0
- package/dist/defaultMapInterfaces.d.ts +1 -0
- package/dist/defaultMapInterfaces.d.ts.map +1 -1
- package/dist/defaultMapInterfaces.js.map +1 -1
- package/dist/intervalCollection.d.ts +36 -6
- package/dist/intervalCollection.d.ts.map +1 -1
- package/dist/intervalCollection.js +31 -8
- package/dist/intervalCollection.js.map +1 -1
- package/dist/intervalIndex/endpointInRangeIndex.d.ts +4 -0
- package/dist/intervalIndex/endpointInRangeIndex.d.ts.map +1 -1
- package/dist/intervalIndex/endpointInRangeIndex.js +3 -0
- package/dist/intervalIndex/endpointInRangeIndex.js.map +1 -1
- package/dist/intervalIndex/endpointIndex.d.ts +6 -0
- package/dist/intervalIndex/endpointIndex.d.ts.map +1 -1
- package/dist/intervalIndex/endpointIndex.js +3 -0
- package/dist/intervalIndex/endpointIndex.js.map +1 -1
- package/dist/intervalIndex/idIntervalIndex.d.ts +6 -0
- package/dist/intervalIndex/idIntervalIndex.d.ts.map +1 -1
- package/dist/intervalIndex/idIntervalIndex.js +3 -0
- package/dist/intervalIndex/idIntervalIndex.js.map +1 -1
- package/dist/intervalIndex/intervalIndex.d.ts +1 -0
- package/dist/intervalIndex/intervalIndex.d.ts.map +1 -1
- package/dist/intervalIndex/intervalIndex.js.map +1 -1
- package/dist/intervalIndex/overlappingIntervalsIndex.d.ts +9 -0
- package/dist/intervalIndex/overlappingIntervalsIndex.d.ts.map +1 -1
- package/dist/intervalIndex/overlappingIntervalsIndex.js +6 -0
- package/dist/intervalIndex/overlappingIntervalsIndex.js.map +1 -1
- package/dist/intervalIndex/overlappingSequenceIntervalsIndex.d.ts +3 -0
- package/dist/intervalIndex/overlappingSequenceIntervalsIndex.d.ts.map +1 -1
- package/dist/intervalIndex/overlappingSequenceIntervalsIndex.js +6 -0
- package/dist/intervalIndex/overlappingSequenceIntervalsIndex.js.map +1 -1
- package/dist/intervalIndex/sequenceIntervalIndexes.d.ts +1 -0
- package/dist/intervalIndex/sequenceIntervalIndexes.d.ts.map +1 -1
- package/dist/intervalIndex/sequenceIntervalIndexes.js.map +1 -1
- package/dist/intervalIndex/startpointInRangeIndex.d.ts +4 -0
- package/dist/intervalIndex/startpointInRangeIndex.d.ts.map +1 -1
- package/dist/intervalIndex/startpointInRangeIndex.js +3 -0
- package/dist/intervalIndex/startpointInRangeIndex.js.map +1 -1
- package/dist/intervals/interval.d.ts +1 -0
- package/dist/intervals/interval.d.ts.map +1 -1
- package/dist/intervals/interval.js +1 -0
- package/dist/intervals/interval.js.map +1 -1
- package/dist/intervals/intervalUtils.d.ts +12 -1
- package/dist/intervals/intervalUtils.d.ts.map +1 -1
- package/dist/intervals/intervalUtils.js +6 -0
- package/dist/intervals/intervalUtils.js.map +1 -1
- package/dist/intervals/sequenceInterval.d.ts +2 -0
- package/dist/intervals/sequenceInterval.d.ts.map +1 -1
- package/dist/intervals/sequenceInterval.js +2 -0
- package/dist/intervals/sequenceInterval.js.map +1 -1
- package/dist/localValues.d.ts.map +1 -1
- package/dist/localValues.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/revertibles.d.ts +1 -1
- package/dist/revertibles.d.ts.map +1 -1
- package/dist/revertibles.js +5 -2
- package/dist/revertibles.js.map +1 -1
- package/dist/sequence.d.ts +7 -3
- package/dist/sequence.d.ts.map +1 -1
- package/dist/sequence.js +9 -4
- package/dist/sequence.js.map +1 -1
- package/dist/sequenceDeltaEvent.d.ts +4 -0
- package/dist/sequenceDeltaEvent.d.ts.map +1 -1
- package/dist/sequenceDeltaEvent.js +3 -0
- package/dist/sequenceDeltaEvent.js.map +1 -1
- package/dist/sequenceFactory.d.ts +3 -0
- package/dist/sequenceFactory.d.ts.map +1 -1
- package/dist/sequenceFactory.js +3 -0
- package/dist/sequenceFactory.js.map +1 -1
- package/dist/sharedIntervalCollection.d.ts +5 -0
- package/dist/sharedIntervalCollection.d.ts.map +1 -1
- package/dist/sharedIntervalCollection.js +2 -0
- package/dist/sharedIntervalCollection.js.map +1 -1
- package/dist/sharedSequence.d.ts +6 -3
- package/dist/sharedSequence.d.ts.map +1 -1
- package/dist/sharedSequence.js +4 -2
- package/dist/sharedSequence.js.map +1 -1
- package/dist/sharedString.d.ts +16 -1
- package/dist/sharedString.d.ts.map +1 -1
- package/dist/sharedString.js +14 -1
- package/dist/sharedString.js.map +1 -1
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/defaultMapInterfaces.d.ts +1 -0
- package/lib/defaultMapInterfaces.d.ts.map +1 -1
- package/lib/defaultMapInterfaces.js.map +1 -1
- package/lib/intervalCollection.d.ts +36 -6
- package/lib/intervalCollection.d.ts.map +1 -1
- package/lib/intervalCollection.js +31 -8
- package/lib/intervalCollection.js.map +1 -1
- package/lib/intervalIndex/endpointInRangeIndex.d.ts +4 -0
- package/lib/intervalIndex/endpointInRangeIndex.d.ts.map +1 -1
- package/lib/intervalIndex/endpointInRangeIndex.js +3 -0
- package/lib/intervalIndex/endpointInRangeIndex.js.map +1 -1
- package/lib/intervalIndex/endpointIndex.d.ts +6 -0
- package/lib/intervalIndex/endpointIndex.d.ts.map +1 -1
- package/lib/intervalIndex/endpointIndex.js +3 -0
- package/lib/intervalIndex/endpointIndex.js.map +1 -1
- package/lib/intervalIndex/idIntervalIndex.d.ts +6 -0
- package/lib/intervalIndex/idIntervalIndex.d.ts.map +1 -1
- package/lib/intervalIndex/idIntervalIndex.js +3 -0
- package/lib/intervalIndex/idIntervalIndex.js.map +1 -1
- package/lib/intervalIndex/intervalIndex.d.ts +1 -0
- package/lib/intervalIndex/intervalIndex.d.ts.map +1 -1
- package/lib/intervalIndex/intervalIndex.js.map +1 -1
- package/lib/intervalIndex/overlappingIntervalsIndex.d.ts +9 -0
- package/lib/intervalIndex/overlappingIntervalsIndex.d.ts.map +1 -1
- package/lib/intervalIndex/overlappingIntervalsIndex.js +6 -0
- package/lib/intervalIndex/overlappingIntervalsIndex.js.map +1 -1
- package/lib/intervalIndex/overlappingSequenceIntervalsIndex.d.ts +3 -0
- package/lib/intervalIndex/overlappingSequenceIntervalsIndex.d.ts.map +1 -1
- package/lib/intervalIndex/overlappingSequenceIntervalsIndex.js +6 -0
- package/lib/intervalIndex/overlappingSequenceIntervalsIndex.js.map +1 -1
- package/lib/intervalIndex/sequenceIntervalIndexes.d.ts +1 -0
- package/lib/intervalIndex/sequenceIntervalIndexes.d.ts.map +1 -1
- package/lib/intervalIndex/sequenceIntervalIndexes.js.map +1 -1
- package/lib/intervalIndex/startpointInRangeIndex.d.ts +4 -0
- package/lib/intervalIndex/startpointInRangeIndex.d.ts.map +1 -1
- package/lib/intervalIndex/startpointInRangeIndex.js +3 -0
- package/lib/intervalIndex/startpointInRangeIndex.js.map +1 -1
- package/lib/intervals/interval.d.ts +1 -0
- package/lib/intervals/interval.d.ts.map +1 -1
- package/lib/intervals/interval.js +1 -0
- package/lib/intervals/interval.js.map +1 -1
- package/lib/intervals/intervalUtils.d.ts +12 -1
- package/lib/intervals/intervalUtils.d.ts.map +1 -1
- package/lib/intervals/intervalUtils.js +6 -0
- package/lib/intervals/intervalUtils.js.map +1 -1
- package/lib/intervals/sequenceInterval.d.ts +2 -0
- package/lib/intervals/sequenceInterval.d.ts.map +1 -1
- package/lib/intervals/sequenceInterval.js +2 -0
- package/lib/intervals/sequenceInterval.js.map +1 -1
- package/lib/localValues.d.ts.map +1 -1
- package/lib/localValues.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/revertibles.d.ts +1 -1
- package/lib/revertibles.d.ts.map +1 -1
- package/lib/revertibles.js +5 -2
- package/lib/revertibles.js.map +1 -1
- package/lib/sequence.d.ts +7 -3
- package/lib/sequence.d.ts.map +1 -1
- package/lib/sequence.js +12 -5
- package/lib/sequence.js.map +1 -1
- package/lib/sequenceDeltaEvent.d.ts +4 -0
- package/lib/sequenceDeltaEvent.d.ts.map +1 -1
- package/lib/sequenceDeltaEvent.js +3 -0
- package/lib/sequenceDeltaEvent.js.map +1 -1
- package/lib/sequenceFactory.d.ts +3 -0
- package/lib/sequenceFactory.d.ts.map +1 -1
- package/lib/sequenceFactory.js +3 -0
- package/lib/sequenceFactory.js.map +1 -1
- package/lib/sharedIntervalCollection.d.ts +5 -0
- package/lib/sharedIntervalCollection.d.ts.map +1 -1
- package/lib/sharedIntervalCollection.js +2 -0
- package/lib/sharedIntervalCollection.js.map +1 -1
- package/lib/sharedSequence.d.ts +6 -3
- package/lib/sharedSequence.d.ts.map +1 -1
- package/lib/sharedSequence.js +4 -2
- package/lib/sharedSequence.js.map +1 -1
- package/lib/sharedString.d.ts +16 -1
- package/lib/sharedString.d.ts.map +1 -1
- package/lib/sharedString.js +14 -1
- package/lib/sharedString.js.map +1 -1
- package/package.json +25 -50
- package/src/defaultMapInterfaces.ts +1 -0
- package/src/intervalCollection.ts +91 -13
- package/src/intervalIndex/endpointInRangeIndex.ts +4 -0
- package/src/intervalIndex/endpointIndex.ts +6 -0
- package/src/intervalIndex/idIntervalIndex.ts +6 -0
- package/src/intervalIndex/intervalIndex.ts +1 -0
- package/src/intervalIndex/overlappingIntervalsIndex.ts +9 -0
- package/src/intervalIndex/overlappingSequenceIntervalsIndex.ts +6 -0
- package/src/intervalIndex/sequenceIntervalIndexes.ts +1 -0
- package/src/intervalIndex/startpointInRangeIndex.ts +4 -1
- package/src/intervals/interval.ts +6 -1
- package/src/intervals/intervalUtils.ts +12 -1
- package/src/intervals/sequenceInterval.ts +2 -0
- package/src/localValues.ts +4 -1
- package/src/packageVersion.ts +1 -1
- package/src/revertibles.ts +6 -3
- package/src/sequence.ts +11 -4
- package/src/sequenceDeltaEvent.ts +4 -0
- package/src/sequenceFactory.ts +3 -0
- package/src/sharedIntervalCollection.ts +5 -0
- package/src/sharedSequence.ts +6 -3
- package/src/sharedString.ts +23 -1
package/lib/sharedString.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { SharedSegmentSequence } from "./sequence";
|
|
|
8
8
|
import { SharedStringFactory } from "./sequenceFactory";
|
|
9
9
|
/**
|
|
10
10
|
* Fluid object interface describing access methods on a SharedString
|
|
11
|
+
* @public
|
|
11
12
|
*/
|
|
12
13
|
export interface ISharedString extends SharedSegmentSequence<SharedStringSegment> {
|
|
13
14
|
/**
|
|
@@ -29,6 +30,9 @@ export interface ISharedString extends SharedSegmentSequence<SharedStringSegment
|
|
|
29
30
|
*/
|
|
30
31
|
posFromRelativePos(relativePos: IRelativePosition): number;
|
|
31
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
32
36
|
export type SharedStringSegment = TextSegment | Marker;
|
|
33
37
|
/**
|
|
34
38
|
* The Shared String is a specialized data structure for handling collaborative
|
|
@@ -39,6 +43,7 @@ export type SharedStringSegment = TextSegment | Marker;
|
|
|
39
43
|
* used to store metadata at positions within the text, like the details of an
|
|
40
44
|
* image or Fluid object that should be rendered with the text.
|
|
41
45
|
*
|
|
46
|
+
* @public
|
|
42
47
|
*/
|
|
43
48
|
export declare class SharedString extends SharedSegmentSequence<SharedStringSegment> implements ISharedString {
|
|
44
49
|
id: string;
|
|
@@ -111,6 +116,7 @@ export declare class SharedString extends SharedSegmentSequence<SharedStringSegm
|
|
|
111
116
|
/**
|
|
112
117
|
* Finds the nearest reference with ReferenceType.Tile to `startPos` in the direction dictated by `tilePrecedesPos`.
|
|
113
118
|
* Note that Markers receive `ReferenceType.Tile` by default.
|
|
119
|
+
* @deprecated Use `searchForMarker` instead.
|
|
114
120
|
* @param startPos - Position at which to start the search
|
|
115
121
|
* @param clientId - clientId dictating the perspective to search from
|
|
116
122
|
* @param tileLabel - Label of the tile to search for
|
|
@@ -120,6 +126,15 @@ export declare class SharedString extends SharedSegmentSequence<SharedStringSegm
|
|
|
120
126
|
tile: ReferencePosition;
|
|
121
127
|
pos: number;
|
|
122
128
|
} | undefined;
|
|
129
|
+
/**
|
|
130
|
+
* Searches a string for the nearest marker in either direction to a given start position.
|
|
131
|
+
* The search will include the start position, so markers at the start position are valid
|
|
132
|
+
* results of the search.
|
|
133
|
+
* @param startPos - Position at which to start the search
|
|
134
|
+
* @param markerLabel - Label of the marker to search for
|
|
135
|
+
* @param forwards - Whether the desired marker comes before (false) or after (true) `startPos`
|
|
136
|
+
*/
|
|
137
|
+
searchForMarker(startPos: number, markerLabel: string, forwards?: boolean): Marker | undefined;
|
|
123
138
|
/**
|
|
124
139
|
* Retrieve text from the SharedString in string format.
|
|
125
140
|
* @param start - The starting index of the text to retrieve, or 0 if omitted.
|
|
@@ -147,7 +162,6 @@ export declare class SharedString extends SharedSegmentSequence<SharedStringSegm
|
|
|
147
162
|
* @param sharedString - String to retrieve text and markers from
|
|
148
163
|
* @param label - label to split on
|
|
149
164
|
* @returns Two parallel lists of text and markers, split by markers with the provided `label`.
|
|
150
|
-
*
|
|
151
165
|
* For example:
|
|
152
166
|
* ```typescript
|
|
153
167
|
* // Say sharedstring has contents "hello<paragraph marker 1>world<paragraph marker 2>missing".
|
|
@@ -156,6 +170,7 @@ export declare class SharedString extends SharedSegmentSequence<SharedStringSegm
|
|
|
156
170
|
* // parallelMarkers === [<paragraph marker 1 object>, <paragraph marker 2 object>]
|
|
157
171
|
* // Note parallelText does not include "missing".
|
|
158
172
|
* ```
|
|
173
|
+
* @public
|
|
159
174
|
*/
|
|
160
175
|
export declare function getTextAndMarkers(sharedString: SharedString, label: string, start?: number, end?: number): {
|
|
161
176
|
parallelText: string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sharedString.d.ts","sourceRoot":"","sources":["../src/sharedString.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,YAAY,EAC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AAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,WAAW,CAAC,EAAE,YAAY;IAIpF;;;;;;;;OAQG;IACI,QAAQ,CACd,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,SAAS,EAAE,MAAM,EACjB,SAAS,UAAO,GAEd;QACA,IAAI,EAAE,iBAAiB,CAAC;QACxB,GAAG,EAAE,MAAM,CAAC;KACX,GACD,SAAS;IAIZ;;;;;;;OAOG;IACI,eAAe,CACrB,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,QAAQ,UAAO,GACb,MAAM,GAAG,SAAS;IAIrB;;;;;OAKG;IACI,OAAO,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM;IAW3C;;OAEG;IACI,uBAAuB,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM;IAWpD,uBAAuB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM;IAWzD;;;OAGG;IACI,eAAe,CAAC,EAAE,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS;IAIxD;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE,eAAe,EAAE,OAAO,GAAG,IAAI;CAOhE;AAWD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAChC,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE,MAAM,EACb,KAAK,CAAC,EAAE,MAAM,EACd,GAAG,CAAC,EAAE,MAAM,GACV;IACF,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,eAAe,EAAE,MAAM,EAAE,CAAC;CAC1B,CAWA"}
|
package/lib/sharedString.js
CHANGED
|
@@ -14,6 +14,7 @@ import { SharedStringFactory } from "./sequenceFactory";
|
|
|
14
14
|
* used to store metadata at positions within the text, like the details of an
|
|
15
15
|
* image or Fluid object that should be rendered with the text.
|
|
16
16
|
*
|
|
17
|
+
* @public
|
|
17
18
|
*/
|
|
18
19
|
export class SharedString extends SharedSegmentSequence {
|
|
19
20
|
/**
|
|
@@ -128,6 +129,7 @@ export class SharedString extends SharedSegmentSequence {
|
|
|
128
129
|
/**
|
|
129
130
|
* Finds the nearest reference with ReferenceType.Tile to `startPos` in the direction dictated by `tilePrecedesPos`.
|
|
130
131
|
* Note that Markers receive `ReferenceType.Tile` by default.
|
|
132
|
+
* @deprecated Use `searchForMarker` instead.
|
|
131
133
|
* @param startPos - Position at which to start the search
|
|
132
134
|
* @param clientId - clientId dictating the perspective to search from
|
|
133
135
|
* @param tileLabel - Label of the tile to search for
|
|
@@ -136,6 +138,17 @@ export class SharedString extends SharedSegmentSequence {
|
|
|
136
138
|
findTile(startPos, tileLabel, preceding = true) {
|
|
137
139
|
return this.client.findTile(startPos ?? 0, tileLabel, preceding);
|
|
138
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Searches a string for the nearest marker in either direction to a given start position.
|
|
143
|
+
* The search will include the start position, so markers at the start position are valid
|
|
144
|
+
* results of the search.
|
|
145
|
+
* @param startPos - Position at which to start the search
|
|
146
|
+
* @param markerLabel - Label of the marker to search for
|
|
147
|
+
* @param forwards - Whether the desired marker comes before (false) or after (true) `startPos`
|
|
148
|
+
*/
|
|
149
|
+
searchForMarker(startPos, markerLabel, forwards = true) {
|
|
150
|
+
return this.client.searchForMarker(startPos, markerLabel, forwards);
|
|
151
|
+
}
|
|
139
152
|
/**
|
|
140
153
|
* Retrieve text from the SharedString in string format.
|
|
141
154
|
* @param start - The starting index of the text to retrieve, or 0 if omitted.
|
|
@@ -181,7 +194,6 @@ export class SharedString extends SharedSegmentSequence {
|
|
|
181
194
|
* @param sharedString - String to retrieve text and markers from
|
|
182
195
|
* @param label - label to split on
|
|
183
196
|
* @returns Two parallel lists of text and markers, split by markers with the provided `label`.
|
|
184
|
-
*
|
|
185
197
|
* For example:
|
|
186
198
|
* ```typescript
|
|
187
199
|
* // Say sharedstring has contents "hello<paragraph marker 1>world<paragraph marker 2>missing".
|
|
@@ -190,6 +202,7 @@ export class SharedString extends SharedSegmentSequence {
|
|
|
190
202
|
* // parallelMarkers === [<paragraph marker 1 object>, <paragraph marker 2 object>]
|
|
191
203
|
* // Note parallelText does not include "missing".
|
|
192
204
|
* ```
|
|
205
|
+
* @public
|
|
193
206
|
*/
|
|
194
207
|
export function getTextAndMarkers(sharedString, label, start, end) {
|
|
195
208
|
const accum = {
|
package/lib/sharedString.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sharedString.js","sourceRoot":"","sources":["../src/sharedString.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAQN,MAAM,EAIN,eAAe,EACf,WAAW,GACX,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAkCxD;;;;;;;;;GASG;AACH,MAAM,OAAO,YACZ,SAAQ,qBAA0C;IAGlD;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,OAA+B,EAAE,EAAW;QAChE,OAAO,OAAO,CAAC,aAAa,CAAC,EAAE,EAAE,mBAAmB,CAAC,IAAI,CAAiB,CAAC;IAC5E,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,UAAU;QACvB,OAAO,IAAI,mBAAmB,EAAE,CAAC;IAClC,CAAC;IAED,IAAW,aAAa;QACvB,OAAO,IAAI,CAAC;IACb,CAAC;IAID,YACC,QAAgC,EACzB,EAAU,EACjB,UAA8B;QAE9B,KAAK,CAAC,QAAQ,EAAE,EAAE,EAAE,UAAU,EAAE,mBAAmB,CAAC,eAAsB,CAAC,CAAC;QAHrE,OAAE,GAAF,EAAE,CAAQ;QAIjB,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAAE,CAAC;IAC3D,CAAC;IAED;;;;;OAKG;IACI,oB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G,IAAI,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC;YAC7C,WAAW,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;SACzD;KACD;SAAM;QACN,IAAI,WAAW,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE;YAC1C,MAAM,eAAe,GACpB,WAAW,KAAK,GAAG;gBAClB,CAAC,CAAC,gEAAgE;oBAChE,KAAK,OAAO,CAAC,QAAQ,EAAE,EAAE;gBAC3B,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;YAC7C,WAAW,CAAC,IAAI,IAAI,eAAe,CAAC;SACpC;aAAM;YACN,MAAM,MAAM,GAAG,OAAiB,CAAC;YACjC,IAAI,eAAe,CAAC,MAAM,EAAE,SAAS,CAAC,mBAAmB,CAAC,EAAE;gBAC3D,SAAS,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBACvC,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;gBAC9C,WAAW,CAAC,IAAI,GAAG,EAAE,CAAC;aACtB;SACD;KACD;IAED,OAAO,IAAI,CAAC;AACb,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tICombiningOp,\n\tIMergeTreeInsertMsg,\n\tIMergeTreeRemoveMsg,\n\tIMergeTreeTextHelper,\n\tIRelativePosition,\n\tISegment,\n\tISegmentAction,\n\tMarker,\n\tPropertySet,\n\tReferencePosition,\n\tReferenceType,\n\trefHasTileLabel,\n\tTextSegment,\n} from \"@fluidframework/merge-tree\";\nimport { IFluidDataStoreRuntime, IChannelAttributes } from \"@fluidframework/datastore-definitions\";\nimport { SharedSegmentSequence } from \"./sequence\";\nimport { SharedStringFactory } from \"./sequenceFactory\";\n\n/**\n * Fluid object interface describing access methods on a SharedString\n */\nexport interface ISharedString extends SharedSegmentSequence<SharedStringSegment> {\n\t/**\n\t * Inserts the text at the position.\n\t * @param pos - The position to insert the text at\n\t * @param text - The text to insert\n\t * @param props - The properties of the text\n\t */\n\tinsertText(pos: number, text: string, props?: PropertySet): void;\n\n\t/**\n\t * Inserts a marker at the position.\n\t * @param pos - The position to insert the marker at\n\t * @param refType - The reference type of the marker\n\t * @param props - The properties of the marker\n\t */\n\tinsertMarker(\n\t\tpos: number,\n\t\trefType: ReferenceType,\n\t\tprops?: PropertySet,\n\t): IMergeTreeInsertMsg | undefined;\n\n\t/**\n\t * {@inheritDoc SharedSegmentSequence.posFromRelativePos}\n\t */\n\tposFromRelativePos(relativePos: IRelativePosition): number;\n}\n\nexport type SharedStringSegment = TextSegment | Marker;\n\n/**\n * The Shared String is a specialized data structure for handling collaborative\n * text. It is based on a more general Sequence data structure but has\n * additional features that make working with text easier.\n *\n * In addition to text, a Shared String can also contain markers. Markers can be\n * used to store metadata at positions within the text, like the details of an\n * image or Fluid object that should be rendered with the text.\n *\n */\nexport class SharedString\n\textends SharedSegmentSequence<SharedStringSegment>\n\timplements ISharedString\n{\n\t/**\n\t * Create a new shared string.\n\t * @param runtime - data store runtime the new shared string belongs to\n\t * @param id - optional name of the shared string\n\t * @returns newly create shared string (but not attached yet)\n\t */\n\tpublic static create(runtime: IFluidDataStoreRuntime, id?: string) {\n\t\treturn runtime.createChannel(id, SharedStringFactory.Type) as SharedString;\n\t}\n\n\t/**\n\t * Get a factory for SharedString to register with the data store.\n\t * @returns a factory that creates and load SharedString\n\t */\n\tpublic static getFactory() {\n\t\treturn new SharedStringFactory();\n\t}\n\n\tpublic get ISharedString(): ISharedString {\n\t\treturn this;\n\t}\n\n\tprivate readonly mergeTreeTextHelper: IMergeTreeTextHelper;\n\n\tconstructor(\n\t\tdocument: IFluidDataStoreRuntime,\n\t\tpublic id: string,\n\t\tattributes: IChannelAttributes,\n\t) {\n\t\tsuper(document, id, attributes, SharedStringFactory.segmentFromSpec as any);\n\t\tthis.mergeTreeTextHelper = this.client.createTextHelper();\n\t}\n\n\t/**\n\t * Inserts a marker at a relative position.\n\t * @param relativePos1 - The relative position to insert the marker at\n\t * @param refType - The reference type of the marker\n\t * @param props - The properties of the marker\n\t */\n\tpublic insertMarkerRelative(\n\t\trelativePos1: IRelativePosition,\n\t\trefType: ReferenceType,\n\t\tprops?: PropertySet,\n\t) {\n\t\tconst segment = new Marker(refType);\n\t\tif (props) {\n\t\t\tsegment.addProperties(props);\n\t\t}\n\n\t\tconst pos = this.posFromRelativePos(relativePos1);\n\t\tthis.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));\n\t}\n\n\t/**\n\t * {@inheritDoc ISharedString.insertMarker}\n\t */\n\tpublic insertMarker(\n\t\tpos: number,\n\t\trefType: ReferenceType,\n\t\tprops?: PropertySet,\n\t): IMergeTreeInsertMsg | undefined {\n\t\tconst segment = new Marker(refType);\n\t\tif (props) {\n\t\t\tsegment.addProperties(props);\n\t\t}\n\n\t\treturn this.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));\n\t}\n\n\t/**\n\t * Inserts the text at the position.\n\t * @param relativePos1 - The relative position to insert the text at\n\t * @param text - The text to insert\n\t * @param props - The properties of text\n\t */\n\tpublic insertTextRelative(relativePos1: IRelativePosition, text: string, props?: PropertySet) {\n\t\tconst segment = new TextSegment(text);\n\t\tif (props) {\n\t\t\tsegment.addProperties(props);\n\t\t}\n\n\t\tconst pos = this.posFromRelativePos(relativePos1);\n\t\tthis.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));\n\t}\n\n\t/**\n\t * {@inheritDoc ISharedString.insertText}\n\t */\n\tpublic insertText(pos: number, text: string, props?: PropertySet) {\n\t\tconst segment = new TextSegment(text);\n\t\tif (props) {\n\t\t\tsegment.addProperties(props);\n\t\t}\n\n\t\tthis.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));\n\t}\n\n\t/**\n\t * Replaces a range with the provided text.\n\t * @param start - The inclusive start of the range to replace\n\t * @param end - The exclusive end of the range to replace\n\t * @param text - The text to replace the range with\n\t * @param props - Optional. The properties of the replacement text\n\t */\n\tpublic replaceText(start: number, end: number, text: string, props?: PropertySet) {\n\t\tthis.replaceRange(start, end, TextSegment.make(text, props));\n\t}\n\n\t/**\n\t * Removes the text in the given range.\n\t * @param start - The inclusive start of the range to remove\n\t * @param end - The exclusive end of the range to replace\n\t * @returns the message sent.\n\t */\n\tpublic removeText(start: number, end: number): IMergeTreeRemoveMsg {\n\t\treturn this.removeRange(start, end);\n\t}\n\n\t/**\n\t * Annotates the marker with the provided properties and calls the callback on consensus.\n\t * @param marker - The marker to annotate\n\t * @param props - The properties to annotate the marker with\n\t * @param consensusCallback - The callback called when consensus is reached\n\t */\n\tpublic annotateMarkerNotifyConsensus(\n\t\tmarker: Marker,\n\t\tprops: PropertySet,\n\t\tcallback: (m: Marker) => void,\n\t) {\n\t\tthis.guardReentrancy(() =>\n\t\t\tthis.client.annotateMarkerNotifyConsensus(marker, props, callback),\n\t\t);\n\t}\n\n\t/**\n\t * Annotates the marker with the provided properties.\n\t * @param marker - The marker to annotate\n\t * @param props - The properties to annotate the marker with\n\t * @param combiningOp - Optional. Specifies how to combine values for the property, such as \"incr\" for increment.\n\t */\n\tpublic annotateMarker(marker: Marker, props: PropertySet, combiningOp?: ICombiningOp) {\n\t\tthis.guardReentrancy(() => this.client.annotateMarker(marker, props, combiningOp));\n\t}\n\n\t/**\n\t * Finds the nearest reference with ReferenceType.Tile to `startPos` in the direction dictated by `tilePrecedesPos`.\n\t * Note that Markers receive `ReferenceType.Tile` by default.\n\t * @param startPos - Position at which to start the search\n\t * @param clientId - clientId dictating the perspective to search from\n\t * @param tileLabel - Label of the tile to search for\n\t * @param preceding - Whether the desired tile comes before (true) or after (false) `startPos`\n\t */\n\tpublic findTile(\n\t\tstartPos: number | undefined,\n\t\ttileLabel: string,\n\t\tpreceding = true,\n\t):\n\t\t| {\n\t\t\t\ttile: ReferencePosition;\n\t\t\t\tpos: number;\n\t\t }\n\t\t| undefined {\n\t\treturn this.client.findTile(startPos ?? 0, tileLabel, preceding);\n\t}\n\n\t/**\n\t * Retrieve text from the SharedString in string format.\n\t * @param start - The starting index of the text to retrieve, or 0 if omitted.\n\t * @param end - The ending index of the text to retrieve, or the end of the string if omitted\n\t * @returns The requested text content as a string.\n\t */\n\tpublic getText(start?: number, end?: number) {\n\t\tconst segmentWindow = this.client.getCollabWindow();\n\t\treturn this.mergeTreeTextHelper.getText(\n\t\t\tsegmentWindow.currentSeq,\n\t\t\tsegmentWindow.clientId,\n\t\t\t\"\",\n\t\t\tstart,\n\t\t\tend,\n\t\t);\n\t}\n\n\t/**\n\t * Adds spaces for markers and handles, so that position calculations account for them.\n\t */\n\tpublic getTextWithPlaceholders(start?: number, end?: number) {\n\t\tconst segmentWindow = this.client.getCollabWindow();\n\t\treturn this.mergeTreeTextHelper.getText(\n\t\t\tsegmentWindow.currentSeq,\n\t\t\tsegmentWindow.clientId,\n\t\t\t\" \",\n\t\t\tstart,\n\t\t\tend,\n\t\t);\n\t}\n\n\tpublic getTextRangeWithMarkers(start: number, end: number) {\n\t\tconst segmentWindow = this.client.getCollabWindow();\n\t\treturn this.mergeTreeTextHelper.getText(\n\t\t\tsegmentWindow.currentSeq,\n\t\t\tsegmentWindow.clientId,\n\t\t\t\"*\",\n\t\t\tstart,\n\t\t\tend,\n\t\t);\n\t}\n\n\t/**\n\t * Looks up and returns a `Marker` using its id. Returns `undefined` if there is no marker with the provided\n\t * id in this `SharedString`.\n\t */\n\tpublic getMarkerFromId(id: string): ISegment | undefined {\n\t\treturn this.client.getMarkerFromId(id);\n\t}\n\n\t/**\n\t * Revert an op\n\t */\n\tprotected rollback(content: any, localOpMetadata: unknown): void {\n\t\tif (this.client.rollback !== undefined) {\n\t\t\tthis.client.rollback(content, localOpMetadata);\n\t\t} else {\n\t\t\tsuper.rollback(content, localOpMetadata);\n\t\t}\n\t}\n}\n\ninterface ITextAndMarkerAccumulator {\n\tparallelText: string[];\n\tparallelMarkers: Marker[];\n\tparallelMarkerLabel: string;\n\tplaceholder?: string;\n\ttagsInProgress: string[];\n\ttextSegment: TextSegment;\n}\n\n/**\n * Splits the text into regions ending with markers with the given `label`.\n * @param sharedString - String to retrieve text and markers from\n * @param label - label to split on\n * @returns Two parallel lists of text and markers, split by markers with the provided `label`.\n *\n * For example:\n * ```typescript\n * // Say sharedstring has contents \"hello<paragraph marker 1>world<paragraph marker 2>missing\".\n * const { parallelText, parallelMarkers } = getTextAndMarkers(sharedString, \"paragraph\");\n * // parallelText === [\"hello\", \"world\"]\n * // parallelMarkers === [<paragraph marker 1 object>, <paragraph marker 2 object>]\n * // Note parallelText does not include \"missing\".\n * ```\n */\nexport function getTextAndMarkers(\n\tsharedString: SharedString,\n\tlabel: string,\n\tstart?: number,\n\tend?: number,\n): {\n\tparallelText: string[];\n\tparallelMarkers: Marker[];\n} {\n\tconst accum: ITextAndMarkerAccumulator = {\n\t\tparallelMarkerLabel: label,\n\t\tparallelMarkers: [],\n\t\tparallelText: [],\n\t\ttagsInProgress: [],\n\t\ttextSegment: new TextSegment(\"\"),\n\t};\n\n\tsharedString.walkSegments(gatherTextAndMarkers, start, end, accum);\n\treturn { parallelText: accum.parallelText, parallelMarkers: accum.parallelMarkers };\n}\n\nconst gatherTextAndMarkers: ISegmentAction<ITextAndMarkerAccumulator> = (\n\tsegment: ISegment,\n\tpos: number,\n\trefSeq: number,\n\tclientId: number,\n\tstart: number,\n\tend: number,\n\taccumText: ITextAndMarkerAccumulator,\n) => {\n\tconst { placeholder, tagsInProgress, textSegment } = accumText;\n\tif (TextSegment.is(segment)) {\n\t\tlet beginTags = \"\";\n\t\tlet endTags = \"\";\n\t\t// TODO: let clients pass in function to get tag\n\t\tconst tags = [] as string[];\n\t\tconst initTags = [] as string[];\n\n\t\tif (segment.properties?.[\"font-weight\"]) {\n\t\t\ttags.push(\"b\");\n\t\t}\n\t\tif (segment.properties?.[\"text-decoration\"]) {\n\t\t\ttags.push(\"u\");\n\t\t}\n\t\tconst remTags = [] as string[];\n\t\tif (tags.length > 0) {\n\t\t\tfor (const tag of tags) {\n\t\t\t\tif (!tagsInProgress.includes(tag)) {\n\t\t\t\t\tbeginTags += `<${tag}>`;\n\t\t\t\t\tinitTags.push(tag);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const accumTag of tagsInProgress) {\n\t\t\t\tif (!tags.includes(accumTag)) {\n\t\t\t\t\tendTags += `</${accumTag}>`;\n\t\t\t\t\tremTags.push(accumTag);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const initTag of initTags.reverse()) {\n\t\t\t\ttagsInProgress.push(initTag);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (const accumTag of tagsInProgress) {\n\t\t\t\tendTags += `</${accumTag}>`;\n\t\t\t\tremTags.push(accumTag);\n\t\t\t}\n\t\t}\n\t\tfor (const remTag of remTags) {\n\t\t\tconst remdex = tagsInProgress.indexOf(remTag);\n\t\t\tif (remdex >= 0) {\n\t\t\t\ttagsInProgress.splice(remdex, 1);\n\t\t\t}\n\t\t}\n\t\ttextSegment.text += endTags;\n\t\ttextSegment.text += beginTags;\n\t\tif (start <= 0 && end >= segment.text.length) {\n\t\t\ttextSegment.text += segment.text;\n\t\t} else {\n\t\t\tconst seglen = segment.text.length;\n\t\t\tconst _start = start < 0 ? 0 : start;\n\t\t\tconst _end = end >= seglen ? undefined : end;\n\t\t\ttextSegment.text += segment.text.substring(_start, _end);\n\t\t}\n\t} else {\n\t\tif (placeholder && placeholder.length > 0) {\n\t\t\tconst placeholderText =\n\t\t\t\tplaceholder === \"*\"\n\t\t\t\t\t? // eslint-disable-next-line @typescript-eslint/no-base-to-string\n\t\t\t\t\t `\\n${segment.toString()}`\n\t\t\t\t\t: placeholder.repeat(segment.cachedLength);\n\t\t\ttextSegment.text += placeholderText;\n\t\t} else {\n\t\t\tconst marker = segment as Marker;\n\t\t\tif (refHasTileLabel(marker, accumText.parallelMarkerLabel)) {\n\t\t\t\taccumText.parallelMarkers.push(marker);\n\t\t\t\taccumText.parallelText.push(textSegment.text);\n\t\t\t\ttextSegment.text = \"\";\n\t\t\t}\n\t\t}\n\t}\n\n\treturn true;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"sharedString.js","sourceRoot":"","sources":["../src/sharedString.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAQN,MAAM,EAIN,eAAe,EACf,WAAW,GACX,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAsCxD;;;;;;;;;;GAUG;AACH,MAAM,OAAO,YACZ,SAAQ,qBAA0C;IAGlD;;;;;OAKG;IACI,MAAM,CAAC,MAAM,CAAC,OAA+B,EAAE,EAAW;QAChE,OAAO,OAAO,CAAC,aAAa,CAAC,EAAE,EAAE,mBAAmB,CAAC,IAAI,CAAiB,CAAC;IAC5E,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,UAAU;QACvB,OAAO,IAAI,mBAAmB,EAAE,CAAC;IAClC,CAAC;IAED,IAAW,aAAa;QACvB,OAAO,IAAI,CAAC;IACb,CAAC;IAID,YACC,QAAgC,EACzB,EAAU,EACjB,UAA8B;QAE9B,KAAK,CAAC,QAAQ,EAAE,EAAE,EAAE,UAAU,EAAE,mBAAmB,CAAC,eAAsB,CAAC,CAAC;QAHrE,OAAE,GAAF,EAAE,CAAQ;QAIjB,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAAE,CAAC;IAC3D,CAAC;IAED;;;;;OAKG;IACI,oBAAoB,CAC1B,YAA+B,EAC/B,OAAsB,EACtB,KAAmB;QAEnB,MAAM,OAAO,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC;QACpC,IAAI,KAAK,EAAE;YACV,OAAO,CAAC,aAAa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AC;YACrC,MAAM,IAAI,GAAG,GAAG,IAAI,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC;YAC7C,WAAW,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;SACzD;KACD;SAAM;QACN,IAAI,WAAW,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE;YAC1C,MAAM,eAAe,GACpB,WAAW,KAAK,GAAG;gBAClB,CAAC,CAAC,gEAAgE;oBAChE,KAAK,OAAO,CAAC,QAAQ,EAAE,EAAE;gBAC3B,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;YAC7C,WAAW,CAAC,IAAI,IAAI,eAAe,CAAC;SACpC;aAAM;YACN,MAAM,MAAM,GAAG,OAAiB,CAAC;YACjC,IAAI,eAAe,CAAC,MAAM,EAAE,SAAS,CAAC,mBAAmB,CAAC,EAAE;gBAC3D,SAAS,CAAC,eAAe,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBACvC,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;gBAC9C,WAAW,CAAC,IAAI,GAAG,EAAE,CAAC;aACtB;SACD;KACD;IAED,OAAO,IAAI,CAAC;AACb,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\tICombiningOp,\n\tIMergeTreeInsertMsg,\n\tIMergeTreeRemoveMsg,\n\tIMergeTreeTextHelper,\n\tIRelativePosition,\n\tISegment,\n\tISegmentAction,\n\tMarker,\n\tPropertySet,\n\tReferencePosition,\n\tReferenceType,\n\trefHasTileLabel,\n\tTextSegment,\n} from \"@fluidframework/merge-tree\";\nimport { IFluidDataStoreRuntime, IChannelAttributes } from \"@fluidframework/datastore-definitions\";\nimport { SharedSegmentSequence } from \"./sequence\";\nimport { SharedStringFactory } from \"./sequenceFactory\";\n\n/**\n * Fluid object interface describing access methods on a SharedString\n * @public\n */\nexport interface ISharedString extends SharedSegmentSequence<SharedStringSegment> {\n\t/**\n\t * Inserts the text at the position.\n\t * @param pos - The position to insert the text at\n\t * @param text - The text to insert\n\t * @param props - The properties of the text\n\t */\n\tinsertText(pos: number, text: string, props?: PropertySet): void;\n\n\t/**\n\t * Inserts a marker at the position.\n\t * @param pos - The position to insert the marker at\n\t * @param refType - The reference type of the marker\n\t * @param props - The properties of the marker\n\t */\n\tinsertMarker(\n\t\tpos: number,\n\t\trefType: ReferenceType,\n\t\tprops?: PropertySet,\n\t): IMergeTreeInsertMsg | undefined;\n\n\t/**\n\t * {@inheritDoc SharedSegmentSequence.posFromRelativePos}\n\t */\n\tposFromRelativePos(relativePos: IRelativePosition): number;\n}\n\n/**\n * @public\n */\nexport type SharedStringSegment = TextSegment | Marker;\n\n/**\n * The Shared String is a specialized data structure for handling collaborative\n * text. It is based on a more general Sequence data structure but has\n * additional features that make working with text easier.\n *\n * In addition to text, a Shared String can also contain markers. Markers can be\n * used to store metadata at positions within the text, like the details of an\n * image or Fluid object that should be rendered with the text.\n *\n * @public\n */\nexport class SharedString\n\textends SharedSegmentSequence<SharedStringSegment>\n\timplements ISharedString\n{\n\t/**\n\t * Create a new shared string.\n\t * @param runtime - data store runtime the new shared string belongs to\n\t * @param id - optional name of the shared string\n\t * @returns newly create shared string (but not attached yet)\n\t */\n\tpublic static create(runtime: IFluidDataStoreRuntime, id?: string) {\n\t\treturn runtime.createChannel(id, SharedStringFactory.Type) as SharedString;\n\t}\n\n\t/**\n\t * Get a factory for SharedString to register with the data store.\n\t * @returns a factory that creates and load SharedString\n\t */\n\tpublic static getFactory() {\n\t\treturn new SharedStringFactory();\n\t}\n\n\tpublic get ISharedString(): ISharedString {\n\t\treturn this;\n\t}\n\n\tprivate readonly mergeTreeTextHelper: IMergeTreeTextHelper;\n\n\tconstructor(\n\t\tdocument: IFluidDataStoreRuntime,\n\t\tpublic id: string,\n\t\tattributes: IChannelAttributes,\n\t) {\n\t\tsuper(document, id, attributes, SharedStringFactory.segmentFromSpec as any);\n\t\tthis.mergeTreeTextHelper = this.client.createTextHelper();\n\t}\n\n\t/**\n\t * Inserts a marker at a relative position.\n\t * @param relativePos1 - The relative position to insert the marker at\n\t * @param refType - The reference type of the marker\n\t * @param props - The properties of the marker\n\t */\n\tpublic insertMarkerRelative(\n\t\trelativePos1: IRelativePosition,\n\t\trefType: ReferenceType,\n\t\tprops?: PropertySet,\n\t) {\n\t\tconst segment = new Marker(refType);\n\t\tif (props) {\n\t\t\tsegment.addProperties(props);\n\t\t}\n\n\t\tconst pos = this.posFromRelativePos(relativePos1);\n\t\tthis.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));\n\t}\n\n\t/**\n\t * {@inheritDoc ISharedString.insertMarker}\n\t */\n\tpublic insertMarker(\n\t\tpos: number,\n\t\trefType: ReferenceType,\n\t\tprops?: PropertySet,\n\t): IMergeTreeInsertMsg | undefined {\n\t\tconst segment = new Marker(refType);\n\t\tif (props) {\n\t\t\tsegment.addProperties(props);\n\t\t}\n\n\t\treturn this.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));\n\t}\n\n\t/**\n\t * Inserts the text at the position.\n\t * @param relativePos1 - The relative position to insert the text at\n\t * @param text - The text to insert\n\t * @param props - The properties of text\n\t */\n\tpublic insertTextRelative(relativePos1: IRelativePosition, text: string, props?: PropertySet) {\n\t\tconst segment = new TextSegment(text);\n\t\tif (props) {\n\t\t\tsegment.addProperties(props);\n\t\t}\n\n\t\tconst pos = this.posFromRelativePos(relativePos1);\n\t\tthis.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));\n\t}\n\n\t/**\n\t * {@inheritDoc ISharedString.insertText}\n\t */\n\tpublic insertText(pos: number, text: string, props?: PropertySet) {\n\t\tconst segment = new TextSegment(text);\n\t\tif (props) {\n\t\t\tsegment.addProperties(props);\n\t\t}\n\n\t\tthis.guardReentrancy(() => this.client.insertSegmentLocal(pos, segment));\n\t}\n\n\t/**\n\t * Replaces a range with the provided text.\n\t * @param start - The inclusive start of the range to replace\n\t * @param end - The exclusive end of the range to replace\n\t * @param text - The text to replace the range with\n\t * @param props - Optional. The properties of the replacement text\n\t */\n\tpublic replaceText(start: number, end: number, text: string, props?: PropertySet) {\n\t\tthis.replaceRange(start, end, TextSegment.make(text, props));\n\t}\n\n\t/**\n\t * Removes the text in the given range.\n\t * @param start - The inclusive start of the range to remove\n\t * @param end - The exclusive end of the range to replace\n\t * @returns the message sent.\n\t */\n\tpublic removeText(start: number, end: number): IMergeTreeRemoveMsg {\n\t\treturn this.removeRange(start, end);\n\t}\n\n\t/**\n\t * Annotates the marker with the provided properties and calls the callback on consensus.\n\t * @param marker - The marker to annotate\n\t * @param props - The properties to annotate the marker with\n\t * @param consensusCallback - The callback called when consensus is reached\n\t */\n\tpublic annotateMarkerNotifyConsensus(\n\t\tmarker: Marker,\n\t\tprops: PropertySet,\n\t\tcallback: (m: Marker) => void,\n\t) {\n\t\tthis.guardReentrancy(() =>\n\t\t\tthis.client.annotateMarkerNotifyConsensus(marker, props, callback),\n\t\t);\n\t}\n\n\t/**\n\t * Annotates the marker with the provided properties.\n\t * @param marker - The marker to annotate\n\t * @param props - The properties to annotate the marker with\n\t * @param combiningOp - Optional. Specifies how to combine values for the property, such as \"incr\" for increment.\n\t */\n\tpublic annotateMarker(marker: Marker, props: PropertySet, combiningOp?: ICombiningOp) {\n\t\tthis.guardReentrancy(() => this.client.annotateMarker(marker, props, combiningOp));\n\t}\n\n\t/**\n\t * Finds the nearest reference with ReferenceType.Tile to `startPos` in the direction dictated by `tilePrecedesPos`.\n\t * Note that Markers receive `ReferenceType.Tile` by default.\n\t * @deprecated Use `searchForMarker` instead.\n\t * @param startPos - Position at which to start the search\n\t * @param clientId - clientId dictating the perspective to search from\n\t * @param tileLabel - Label of the tile to search for\n\t * @param preceding - Whether the desired tile comes before (true) or after (false) `startPos`\n\t */\n\tpublic findTile(\n\t\tstartPos: number | undefined,\n\t\ttileLabel: string,\n\t\tpreceding = true,\n\t):\n\t\t| {\n\t\t\t\ttile: ReferencePosition;\n\t\t\t\tpos: number;\n\t\t }\n\t\t| undefined {\n\t\treturn this.client.findTile(startPos ?? 0, tileLabel, preceding);\n\t}\n\n\t/**\n\t * Searches a string for the nearest marker in either direction to a given start position.\n\t * The search will include the start position, so markers at the start position are valid\n\t * results of the search.\n\t * @param startPos - Position at which to start the search\n\t * @param markerLabel - Label of the marker to search for\n\t * @param forwards - Whether the desired marker comes before (false) or after (true) `startPos`\n\t */\n\tpublic searchForMarker(\n\t\tstartPos: number,\n\t\tmarkerLabel: string,\n\t\tforwards = true,\n\t): Marker | undefined {\n\t\treturn this.client.searchForMarker(startPos, markerLabel, forwards);\n\t}\n\n\t/**\n\t * Retrieve text from the SharedString in string format.\n\t * @param start - The starting index of the text to retrieve, or 0 if omitted.\n\t * @param end - The ending index of the text to retrieve, or the end of the string if omitted\n\t * @returns The requested text content as a string.\n\t */\n\tpublic getText(start?: number, end?: number) {\n\t\tconst segmentWindow = this.client.getCollabWindow();\n\t\treturn this.mergeTreeTextHelper.getText(\n\t\t\tsegmentWindow.currentSeq,\n\t\t\tsegmentWindow.clientId,\n\t\t\t\"\",\n\t\t\tstart,\n\t\t\tend,\n\t\t);\n\t}\n\n\t/**\n\t * Adds spaces for markers and handles, so that position calculations account for them.\n\t */\n\tpublic getTextWithPlaceholders(start?: number, end?: number) {\n\t\tconst segmentWindow = this.client.getCollabWindow();\n\t\treturn this.mergeTreeTextHelper.getText(\n\t\t\tsegmentWindow.currentSeq,\n\t\t\tsegmentWindow.clientId,\n\t\t\t\" \",\n\t\t\tstart,\n\t\t\tend,\n\t\t);\n\t}\n\n\tpublic getTextRangeWithMarkers(start: number, end: number) {\n\t\tconst segmentWindow = this.client.getCollabWindow();\n\t\treturn this.mergeTreeTextHelper.getText(\n\t\t\tsegmentWindow.currentSeq,\n\t\t\tsegmentWindow.clientId,\n\t\t\t\"*\",\n\t\t\tstart,\n\t\t\tend,\n\t\t);\n\t}\n\n\t/**\n\t * Looks up and returns a `Marker` using its id. Returns `undefined` if there is no marker with the provided\n\t * id in this `SharedString`.\n\t */\n\tpublic getMarkerFromId(id: string): ISegment | undefined {\n\t\treturn this.client.getMarkerFromId(id);\n\t}\n\n\t/**\n\t * Revert an op\n\t */\n\tprotected rollback(content: any, localOpMetadata: unknown): void {\n\t\tif (this.client.rollback !== undefined) {\n\t\t\tthis.client.rollback(content, localOpMetadata);\n\t\t} else {\n\t\t\tsuper.rollback(content, localOpMetadata);\n\t\t}\n\t}\n}\n\ninterface ITextAndMarkerAccumulator {\n\tparallelText: string[];\n\tparallelMarkers: Marker[];\n\tparallelMarkerLabel: string;\n\tplaceholder?: string;\n\ttagsInProgress: string[];\n\ttextSegment: TextSegment;\n}\n\n/**\n * Splits the text into regions ending with markers with the given `label`.\n * @param sharedString - String to retrieve text and markers from\n * @param label - label to split on\n * @returns Two parallel lists of text and markers, split by markers with the provided `label`.\n * For example:\n * ```typescript\n * // Say sharedstring has contents \"hello<paragraph marker 1>world<paragraph marker 2>missing\".\n * const { parallelText, parallelMarkers } = getTextAndMarkers(sharedString, \"paragraph\");\n * // parallelText === [\"hello\", \"world\"]\n * // parallelMarkers === [<paragraph marker 1 object>, <paragraph marker 2 object>]\n * // Note parallelText does not include \"missing\".\n * ```\n * @public\n */\nexport function getTextAndMarkers(\n\tsharedString: SharedString,\n\tlabel: string,\n\tstart?: number,\n\tend?: number,\n): {\n\tparallelText: string[];\n\tparallelMarkers: Marker[];\n} {\n\tconst accum: ITextAndMarkerAccumulator = {\n\t\tparallelMarkerLabel: label,\n\t\tparallelMarkers: [],\n\t\tparallelText: [],\n\t\ttagsInProgress: [],\n\t\ttextSegment: new TextSegment(\"\"),\n\t};\n\n\tsharedString.walkSegments(gatherTextAndMarkers, start, end, accum);\n\treturn { parallelText: accum.parallelText, parallelMarkers: accum.parallelMarkers };\n}\n\nconst gatherTextAndMarkers: ISegmentAction<ITextAndMarkerAccumulator> = (\n\tsegment: ISegment,\n\tpos: number,\n\trefSeq: number,\n\tclientId: number,\n\tstart: number,\n\tend: number,\n\taccumText: ITextAndMarkerAccumulator,\n) => {\n\tconst { placeholder, tagsInProgress, textSegment } = accumText;\n\tif (TextSegment.is(segment)) {\n\t\tlet beginTags = \"\";\n\t\tlet endTags = \"\";\n\t\t// TODO: let clients pass in function to get tag\n\t\tconst tags = [] as string[];\n\t\tconst initTags = [] as string[];\n\n\t\tif (segment.properties?.[\"font-weight\"]) {\n\t\t\ttags.push(\"b\");\n\t\t}\n\t\tif (segment.properties?.[\"text-decoration\"]) {\n\t\t\ttags.push(\"u\");\n\t\t}\n\t\tconst remTags = [] as string[];\n\t\tif (tags.length > 0) {\n\t\t\tfor (const tag of tags) {\n\t\t\t\tif (!tagsInProgress.includes(tag)) {\n\t\t\t\t\tbeginTags += `<${tag}>`;\n\t\t\t\t\tinitTags.push(tag);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const accumTag of tagsInProgress) {\n\t\t\t\tif (!tags.includes(accumTag)) {\n\t\t\t\t\tendTags += `</${accumTag}>`;\n\t\t\t\t\tremTags.push(accumTag);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const initTag of initTags.reverse()) {\n\t\t\t\ttagsInProgress.push(initTag);\n\t\t\t}\n\t\t} else {\n\t\t\tfor (const accumTag of tagsInProgress) {\n\t\t\t\tendTags += `</${accumTag}>`;\n\t\t\t\tremTags.push(accumTag);\n\t\t\t}\n\t\t}\n\t\tfor (const remTag of remTags) {\n\t\t\tconst remdex = tagsInProgress.indexOf(remTag);\n\t\t\tif (remdex >= 0) {\n\t\t\t\ttagsInProgress.splice(remdex, 1);\n\t\t\t}\n\t\t}\n\t\ttextSegment.text += endTags;\n\t\ttextSegment.text += beginTags;\n\t\tif (start <= 0 && end >= segment.text.length) {\n\t\t\ttextSegment.text += segment.text;\n\t\t} else {\n\t\t\tconst seglen = segment.text.length;\n\t\t\tconst _start = start < 0 ? 0 : start;\n\t\t\tconst _end = end >= seglen ? undefined : end;\n\t\t\ttextSegment.text += segment.text.substring(_start, _end);\n\t\t}\n\t} else {\n\t\tif (placeholder && placeholder.length > 0) {\n\t\t\tconst placeholderText =\n\t\t\t\tplaceholder === \"*\"\n\t\t\t\t\t? // eslint-disable-next-line @typescript-eslint/no-base-to-string\n\t\t\t\t\t `\\n${segment.toString()}`\n\t\t\t\t\t: placeholder.repeat(segment.cachedLength);\n\t\t\ttextSegment.text += placeholderText;\n\t\t} else {\n\t\t\tconst marker = segment as Marker;\n\t\t\tif (refHasTileLabel(marker, accumText.parallelMarkerLabel)) {\n\t\t\t\taccumText.parallelMarkers.push(marker);\n\t\t\t\taccumText.parallelText.push(textSegment.text);\n\t\t\t\ttextSegment.text = \"\";\n\t\t\t}\n\t\t}\n\t}\n\n\treturn true;\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/sequence",
|
|
3
|
-
"version": "2.0.0-internal.7.
|
|
3
|
+
"version": "2.0.0-internal.7.2.0",
|
|
4
4
|
"description": "Distributed sequence",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -35,44 +35,43 @@
|
|
|
35
35
|
"temp-directory": "nyc/.nyc_output"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@fluid-internal/client-utils": ">=2.0.0-internal.7.
|
|
39
|
-
"@fluidframework/core-interfaces": ">=2.0.0-internal.7.
|
|
40
|
-
"@fluidframework/core-utils": ">=2.0.0-internal.7.
|
|
41
|
-
"@fluidframework/datastore-definitions": ">=2.0.0-internal.7.
|
|
42
|
-
"@fluidframework/merge-tree": ">=2.0.0-internal.7.
|
|
38
|
+
"@fluid-internal/client-utils": ">=2.0.0-internal.7.2.0 <2.0.0-internal.7.3.0",
|
|
39
|
+
"@fluidframework/core-interfaces": ">=2.0.0-internal.7.2.0 <2.0.0-internal.7.3.0",
|
|
40
|
+
"@fluidframework/core-utils": ">=2.0.0-internal.7.2.0 <2.0.0-internal.7.3.0",
|
|
41
|
+
"@fluidframework/datastore-definitions": ">=2.0.0-internal.7.2.0 <2.0.0-internal.7.3.0",
|
|
42
|
+
"@fluidframework/merge-tree": ">=2.0.0-internal.7.2.0 <2.0.0-internal.7.3.0",
|
|
43
43
|
"@fluidframework/protocol-definitions": "^3.0.0",
|
|
44
|
-
"@fluidframework/runtime-definitions": ">=2.0.0-internal.7.
|
|
45
|
-
"@fluidframework/runtime-utils": ">=2.0.0-internal.7.
|
|
46
|
-
"@fluidframework/shared-object-base": ">=2.0.0-internal.7.
|
|
47
|
-
"@fluidframework/telemetry-utils": ">=2.0.0-internal.7.
|
|
44
|
+
"@fluidframework/runtime-definitions": ">=2.0.0-internal.7.2.0 <2.0.0-internal.7.3.0",
|
|
45
|
+
"@fluidframework/runtime-utils": ">=2.0.0-internal.7.2.0 <2.0.0-internal.7.3.0",
|
|
46
|
+
"@fluidframework/shared-object-base": ">=2.0.0-internal.7.2.0 <2.0.0-internal.7.3.0",
|
|
47
|
+
"@fluidframework/telemetry-utils": ">=2.0.0-internal.7.2.0 <2.0.0-internal.7.3.0",
|
|
48
48
|
"uuid": "^9.0.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@fluid-internal/stochastic-test-utils": ">=2.0.0-internal.7.
|
|
52
|
-
"@fluid-internal/test-dds-utils": ">=2.0.0-internal.7.
|
|
51
|
+
"@fluid-internal/stochastic-test-utils": ">=2.0.0-internal.7.2.0 <2.0.0-internal.7.3.0",
|
|
52
|
+
"@fluid-internal/test-dds-utils": ">=2.0.0-internal.7.2.0 <2.0.0-internal.7.3.0",
|
|
53
53
|
"@fluid-tools/benchmark": "^0.48.0",
|
|
54
|
-
"@fluid-tools/build-cli": "^0.
|
|
55
|
-
"@fluidframework/build-common": "^2.0.
|
|
56
|
-
"@fluidframework/build-tools": "^0.
|
|
57
|
-
"@fluidframework/eslint-config-fluid": "^
|
|
58
|
-
"@fluidframework/mocha-test-setup": ">=2.0.0-internal.7.
|
|
59
|
-
"@fluidframework/sequence-previous": "npm:@fluidframework/sequence@2.0.0-internal.
|
|
60
|
-
"@fluidframework/test-runtime-utils": ">=2.0.0-internal.7.
|
|
54
|
+
"@fluid-tools/build-cli": "^0.26.1",
|
|
55
|
+
"@fluidframework/build-common": "^2.0.3",
|
|
56
|
+
"@fluidframework/build-tools": "^0.26.1",
|
|
57
|
+
"@fluidframework/eslint-config-fluid": "^3.0.0",
|
|
58
|
+
"@fluidframework/mocha-test-setup": ">=2.0.0-internal.7.2.0 <2.0.0-internal.7.3.0",
|
|
59
|
+
"@fluidframework/sequence-previous": "npm:@fluidframework/sequence@2.0.0-internal.7.1.0",
|
|
60
|
+
"@fluidframework/test-runtime-utils": ">=2.0.0-internal.7.2.0 <2.0.0-internal.7.3.0",
|
|
61
61
|
"@microsoft/api-extractor": "^7.37.0",
|
|
62
62
|
"@types/diff": "^3.5.1",
|
|
63
63
|
"@types/mocha": "^9.1.1",
|
|
64
64
|
"@types/node": "^16.18.38",
|
|
65
65
|
"@types/random-js": "^1.0.31",
|
|
66
66
|
"c8": "^7.7.1",
|
|
67
|
-
"copyfiles": "^2.4.1",
|
|
68
67
|
"cross-env": "^7.0.3",
|
|
69
68
|
"diff": "^3.5.0",
|
|
70
|
-
"eslint": "~8.
|
|
69
|
+
"eslint": "~8.50.0",
|
|
71
70
|
"mocha": "^10.2.0",
|
|
72
71
|
"mocha-json-output-reporter": "^2.0.1",
|
|
73
72
|
"mocha-multi-reporters": "^1.5.1",
|
|
74
73
|
"moment": "^2.21.0",
|
|
75
|
-
"prettier": "~
|
|
74
|
+
"prettier": "~3.0.3",
|
|
76
75
|
"random-js": "^1.0.8",
|
|
77
76
|
"rimraf": "^4.4.0",
|
|
78
77
|
"typescript": "~5.1.6"
|
|
@@ -87,32 +86,8 @@
|
|
|
87
86
|
},
|
|
88
87
|
"typeValidation": {
|
|
89
88
|
"broken": {
|
|
90
|
-
"
|
|
91
|
-
"backCompat": false
|
|
92
|
-
},
|
|
93
|
-
"InterfaceDeclaration_IntervalLocator": {
|
|
89
|
+
"ClassDeclaration_SharedString": {
|
|
94
90
|
"forwardCompat": false
|
|
95
|
-
},
|
|
96
|
-
"TypeAliasDeclaration_IntervalRevertible": {
|
|
97
|
-
"forwardCompat": false
|
|
98
|
-
},
|
|
99
|
-
"ClassDeclaration_SequenceInterval": {
|
|
100
|
-
"forwardCompat": false
|
|
101
|
-
},
|
|
102
|
-
"TypeAliasDeclaration_SerializedIntervalDelta": {
|
|
103
|
-
"backCompat": false
|
|
104
|
-
},
|
|
105
|
-
"TypeAliasDeclaration_SharedStringRevertible": {
|
|
106
|
-
"forwardCompat": false
|
|
107
|
-
},
|
|
108
|
-
"InterfaceDeclaration_SequenceOptions": {
|
|
109
|
-
"forwardCompat": false
|
|
110
|
-
},
|
|
111
|
-
"VariableDeclaration_sequenceIntervalHelpers": {
|
|
112
|
-
"backCompat": false
|
|
113
|
-
},
|
|
114
|
-
"InterfaceDeclaration_IIntervalHelpers": {
|
|
115
|
-
"backCompat": false
|
|
116
91
|
}
|
|
117
92
|
}
|
|
118
93
|
},
|
|
@@ -120,12 +95,12 @@
|
|
|
120
95
|
"build": "fluid-build . --task build",
|
|
121
96
|
"build:commonjs": "fluid-build . --task commonjs",
|
|
122
97
|
"build:compile": "fluid-build . --task compile",
|
|
123
|
-
"build:docs": "api-extractor run --local
|
|
98
|
+
"build:docs": "api-extractor run --local",
|
|
124
99
|
"build:esnext": "tsc --project ./tsconfig.esnext.json",
|
|
125
100
|
"build:genver": "gen-version",
|
|
126
101
|
"build:test": "tsc --project ./src/test/tsconfig.json",
|
|
127
|
-
"ci:build:docs": "api-extractor run
|
|
128
|
-
"clean": "rimraf --glob
|
|
102
|
+
"ci:build:docs": "api-extractor run",
|
|
103
|
+
"clean": "rimraf --glob dist lib \"*.tsbuildinfo\" \"*.build.log\" _api-extractor-temp nyc",
|
|
129
104
|
"eslint": "eslint --format stylish src",
|
|
130
105
|
"eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
|
|
131
106
|
"format": "npm run prettier:fix",
|
|
@@ -88,6 +88,7 @@ import {
|
|
|
88
88
|
* If a SequencePlace is the endpoint of a range (e.g. start/end of an interval or search range),
|
|
89
89
|
* the Side value means it is exclusive if it is nearer to the other position and inclusive if it is farther.
|
|
90
90
|
* E.g. the start of a range with Side.After is exclusive of the character at the position.
|
|
91
|
+
* @public
|
|
91
92
|
*/
|
|
92
93
|
export type SequencePlace = number | "start" | "end" | InteriorSequencePlace;
|
|
93
94
|
|
|
@@ -95,6 +96,7 @@ export type SequencePlace = number | "start" | "end" | InteriorSequencePlace;
|
|
|
95
96
|
* A sequence place that does not refer to the special endpoint segments.
|
|
96
97
|
*
|
|
97
98
|
* See {@link SequencePlace} for additional context.
|
|
99
|
+
* @public
|
|
98
100
|
*/
|
|
99
101
|
export interface InteriorSequencePlace {
|
|
100
102
|
pos: number;
|
|
@@ -105,6 +107,7 @@ export interface InteriorSequencePlace {
|
|
|
105
107
|
* Defines a side relative to a character in a sequence.
|
|
106
108
|
*
|
|
107
109
|
* @remarks See {@link SequencePlace} for additional context on usage.
|
|
110
|
+
* @public
|
|
108
111
|
*/
|
|
109
112
|
export enum Side {
|
|
110
113
|
Before = 0,
|
|
@@ -620,6 +623,9 @@ export function makeOpsMap<T extends ISerializableInterval>(): Map<
|
|
|
620
623
|
]);
|
|
621
624
|
}
|
|
622
625
|
|
|
626
|
+
/**
|
|
627
|
+
* @public
|
|
628
|
+
*/
|
|
623
629
|
export type DeserializeCallback = (properties: PropertySet) => void;
|
|
624
630
|
|
|
625
631
|
class IntervalCollectionIterator<TInterval extends ISerializableInterval>
|
|
@@ -657,6 +663,7 @@ class IntervalCollectionIterator<TInterval extends ISerializableInterval>
|
|
|
657
663
|
|
|
658
664
|
/**
|
|
659
665
|
* Change events emitted by `IntervalCollection`s
|
|
666
|
+
* @public
|
|
660
667
|
*/
|
|
661
668
|
export interface IIntervalCollectionEvent<TInterval extends ISerializableInterval> extends IEvent {
|
|
662
669
|
/**
|
|
@@ -715,9 +722,16 @@ export interface IIntervalCollectionEvent<TInterval extends ISerializableInterva
|
|
|
715
722
|
);
|
|
716
723
|
}
|
|
717
724
|
|
|
725
|
+
// solely for type checking in the implementation of add - will be removed once
|
|
726
|
+
// deprecated signatures are removed
|
|
727
|
+
const isSequencePlace = (place: any): place is SequencePlace => {
|
|
728
|
+
return typeof place === "number" || typeof place === "string" || place.pos !== undefined;
|
|
729
|
+
};
|
|
730
|
+
|
|
718
731
|
/**
|
|
719
732
|
* Collection of intervals that supports addition, modification, removal, and efficient spatial querying.
|
|
720
733
|
* Changes to this collection will be incur updates on collaborating clients (i.e. they are not local-only).
|
|
734
|
+
* @public
|
|
721
735
|
*/
|
|
722
736
|
export interface IIntervalCollection<TInterval extends ISerializableInterval>
|
|
723
737
|
extends TypedEventEmitter<IIntervalCollectionEvent<TInterval>> {
|
|
@@ -746,10 +760,10 @@ export interface IIntervalCollection<TInterval extends ISerializableInterval>
|
|
|
746
760
|
getIntervalById(id: string): TInterval | undefined;
|
|
747
761
|
/**
|
|
748
762
|
* Creates a new interval and add it to the collection.
|
|
749
|
-
* @
|
|
750
|
-
* @param
|
|
751
|
-
* @param
|
|
752
|
-
* Intervals may not be Transient.
|
|
763
|
+
* @deprecated call IntervalCollection.add without specifying an intervalType
|
|
764
|
+
* @param start - interval start position (inclusive)
|
|
765
|
+
* @param end - interval end position (exclusive)
|
|
766
|
+
* @param intervalType - type of the interval. All intervals are SlideOnRemove. Intervals may not be Transient.
|
|
753
767
|
* @param props - properties of the interval
|
|
754
768
|
* @returns The created interval
|
|
755
769
|
* @remarks See documentation on {@link SequenceInterval} for comments on
|
|
@@ -823,6 +837,24 @@ export interface IIntervalCollection<TInterval extends ISerializableInterval>
|
|
|
823
837
|
intervalType: IntervalType,
|
|
824
838
|
props?: PropertySet,
|
|
825
839
|
): TInterval;
|
|
840
|
+
/**
|
|
841
|
+
* Creates a new interval and add it to the collection.
|
|
842
|
+
* @param start - interval start position (inclusive)
|
|
843
|
+
* @param end - interval end position (exclusive)
|
|
844
|
+
* @param props - properties of the interval
|
|
845
|
+
* @returns - the created interval
|
|
846
|
+
* @remarks - See documentation on {@link SequenceInterval} for comments on interval endpoint semantics: there are subtleties
|
|
847
|
+
* with how the current half-open behavior is represented.
|
|
848
|
+
*/
|
|
849
|
+
add({
|
|
850
|
+
start,
|
|
851
|
+
end,
|
|
852
|
+
props,
|
|
853
|
+
}: {
|
|
854
|
+
start: SequencePlace;
|
|
855
|
+
end: SequencePlace;
|
|
856
|
+
props?: PropertySet;
|
|
857
|
+
}): TInterval;
|
|
826
858
|
/**
|
|
827
859
|
* Removes an interval from the collection.
|
|
828
860
|
* @param id - Id of the interval to remove
|
|
@@ -839,8 +871,8 @@ export interface IIntervalCollection<TInterval extends ISerializableInterval>
|
|
|
839
871
|
/**
|
|
840
872
|
* Changes the endpoints of an existing interval.
|
|
841
873
|
* @param id - Id of the interval to change
|
|
842
|
-
* @param start - New start value.
|
|
843
|
-
* @param end - New end value.
|
|
874
|
+
* @param start - New start value. To leave the endpoint unchanged, pass the current value.
|
|
875
|
+
* @param end - New end value. To leave the endpoint unchanged, pass the current value.
|
|
844
876
|
* @returns the interval that was changed, if it existed in the collection.
|
|
845
877
|
*/
|
|
846
878
|
change(id: string, start: SequencePlace, end: SequencePlace): TInterval | undefined;
|
|
@@ -1180,21 +1212,64 @@ export class IntervalCollection<TInterval extends ISerializableInterval>
|
|
|
1180
1212
|
|
|
1181
1213
|
/**
|
|
1182
1214
|
* {@inheritdoc IIntervalCollection.add}
|
|
1215
|
+
* @deprecated call IntervalCollection.add without specifying an intervalType
|
|
1183
1216
|
*/
|
|
1184
1217
|
public add(
|
|
1185
1218
|
start: SequencePlace,
|
|
1186
1219
|
end: SequencePlace,
|
|
1187
1220
|
intervalType: IntervalType,
|
|
1188
1221
|
props?: PropertySet,
|
|
1222
|
+
): TInterval;
|
|
1223
|
+
|
|
1224
|
+
public add({
|
|
1225
|
+
start,
|
|
1226
|
+
end,
|
|
1227
|
+
props,
|
|
1228
|
+
}: {
|
|
1229
|
+
start: SequencePlace;
|
|
1230
|
+
end: SequencePlace;
|
|
1231
|
+
props?: PropertySet;
|
|
1232
|
+
}): TInterval;
|
|
1233
|
+
|
|
1234
|
+
public add(
|
|
1235
|
+
start:
|
|
1236
|
+
| SequencePlace
|
|
1237
|
+
| {
|
|
1238
|
+
start: SequencePlace;
|
|
1239
|
+
end: SequencePlace;
|
|
1240
|
+
props?: PropertySet;
|
|
1241
|
+
},
|
|
1242
|
+
end?: SequencePlace,
|
|
1243
|
+
intervalType?: IntervalType,
|
|
1244
|
+
props?: PropertySet,
|
|
1189
1245
|
): TInterval {
|
|
1246
|
+
let intStart: SequencePlace;
|
|
1247
|
+
let intEnd: SequencePlace;
|
|
1248
|
+
let type: IntervalType;
|
|
1249
|
+
let properties: PropertySet | undefined;
|
|
1250
|
+
|
|
1251
|
+
if (isSequencePlace(start)) {
|
|
1252
|
+
intStart = start;
|
|
1253
|
+
assert(end !== undefined, 0x7c0 /* end must be defined */);
|
|
1254
|
+
intEnd = end;
|
|
1255
|
+
assert(intervalType !== undefined, 0x7c1 /* intervalType must be defined */);
|
|
1256
|
+
type = intervalType;
|
|
1257
|
+
properties = props;
|
|
1258
|
+
} else {
|
|
1259
|
+
intStart = start.start;
|
|
1260
|
+
intEnd = start.end;
|
|
1261
|
+
type = IntervalType.SlideOnRemove;
|
|
1262
|
+
properties = start.props;
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1190
1265
|
if (!this.localCollection) {
|
|
1191
1266
|
throw new LoggingError("attach must be called prior to adding intervals");
|
|
1192
1267
|
}
|
|
1193
|
-
if (
|
|
1268
|
+
if (type & IntervalType.Transient) {
|
|
1194
1269
|
throw new LoggingError("Can not add transient intervals");
|
|
1195
1270
|
}
|
|
1196
1271
|
|
|
1197
|
-
const { startSide, endSide, startPos, endPos } = endpointPosAndSide(
|
|
1272
|
+
const { startSide, endSide, startPos, endPos } = endpointPosAndSide(intStart, intEnd);
|
|
1198
1273
|
|
|
1199
1274
|
assert(
|
|
1200
1275
|
startPos !== undefined &&
|
|
@@ -1206,13 +1281,13 @@ export class IntervalCollection<TInterval extends ISerializableInterval>
|
|
|
1206
1281
|
|
|
1207
1282
|
const stickiness = computeStickinessFromSide(startPos, startSide, endPos, endSide);
|
|
1208
1283
|
|
|
1209
|
-
this.assertStickinessEnabled(
|
|
1284
|
+
this.assertStickinessEnabled(intStart, intEnd);
|
|
1210
1285
|
|
|
1211
1286
|
const interval: TInterval = this.localCollection.addInterval(
|
|
1212
1287
|
toSequencePlace(startPos, startSide),
|
|
1213
1288
|
toSequencePlace(endPos, endSide),
|
|
1214
|
-
|
|
1215
|
-
|
|
1289
|
+
type,
|
|
1290
|
+
properties,
|
|
1216
1291
|
);
|
|
1217
1292
|
|
|
1218
1293
|
if (interval) {
|
|
@@ -1223,7 +1298,7 @@ export class IntervalCollection<TInterval extends ISerializableInterval>
|
|
|
1223
1298
|
const serializedInterval: ISerializedInterval = {
|
|
1224
1299
|
start: startPos,
|
|
1225
1300
|
end: endPos,
|
|
1226
|
-
intervalType,
|
|
1301
|
+
intervalType: type,
|
|
1227
1302
|
properties: interval.properties,
|
|
1228
1303
|
sequenceNumber: this.client?.getCurrentSeq() ?? 0,
|
|
1229
1304
|
stickiness,
|
|
@@ -1329,7 +1404,7 @@ export class IntervalCollection<TInterval extends ISerializableInterval>
|
|
|
1329
1404
|
/**
|
|
1330
1405
|
* {@inheritdoc IIntervalCollection.change}
|
|
1331
1406
|
*/
|
|
1332
|
-
public change(id: string, start: SequencePlace, end: SequencePlace)
|
|
1407
|
+
public change(id: string, start: SequencePlace, end: SequencePlace) {
|
|
1333
1408
|
if (!this.localCollection) {
|
|
1334
1409
|
throw new LoggingError("Attach must be called before accessing intervals");
|
|
1335
1410
|
}
|
|
@@ -1582,6 +1657,7 @@ export class IntervalCollection<TInterval extends ISerializableInterval>
|
|
|
1582
1657
|
|
|
1583
1658
|
if (
|
|
1584
1659
|
opName === "change" &&
|
|
1660
|
+
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- ?? is not logically equivalent when .hasPendingChangeStart returns false.
|
|
1585
1661
|
(this.hasPendingChangeStart(intervalId) || this.hasPendingChangeEnd(intervalId))
|
|
1586
1662
|
) {
|
|
1587
1663
|
this.removePendingChange(serializedInterval);
|
|
@@ -1956,6 +2032,7 @@ function setSlideOnRemove(lref: LocalReferencePosition) {
|
|
|
1956
2032
|
|
|
1957
2033
|
/**
|
|
1958
2034
|
* Information that identifies an interval within a `Sequence`.
|
|
2035
|
+
* @public
|
|
1959
2036
|
*/
|
|
1960
2037
|
export interface IntervalLocator {
|
|
1961
2038
|
/**
|
|
@@ -1973,6 +2050,7 @@ export interface IntervalLocator {
|
|
|
1973
2050
|
* @returns undefined if the reference position is not the endpoint of any interval (e.g. it was created
|
|
1974
2051
|
* on the merge tree directly by app code), otherwise an {@link IntervalLocator} for the interval this
|
|
1975
2052
|
* endpoint is a part of.
|
|
2053
|
+
* @public
|
|
1976
2054
|
*/
|
|
1977
2055
|
export function intervalLocatorFromEndpoint(
|
|
1978
2056
|
potentialEndpoint: LocalReferencePosition,
|
|
@@ -20,6 +20,7 @@ import { HasComparisonOverride, compareOverrideables, forceCompare } from "./int
|
|
|
20
20
|
* Collection of intervals.
|
|
21
21
|
*
|
|
22
22
|
* Provide additional APIs to support efficiently querying a collection of intervals whose endpoints fall within a specified range.
|
|
23
|
+
* @public
|
|
23
24
|
*/
|
|
24
25
|
export interface IEndpointInRangeIndex<TInterval extends ISerializableInterval>
|
|
25
26
|
extends IntervalIndex<TInterval> {
|
|
@@ -104,6 +105,9 @@ export class EndpointInRangeIndex<TInterval extends ISerializableInterval>
|
|
|
104
105
|
}
|
|
105
106
|
}
|
|
106
107
|
|
|
108
|
+
/**
|
|
109
|
+
* @public
|
|
110
|
+
*/
|
|
107
111
|
export function createEndpointInRangeIndex(
|
|
108
112
|
sharedString: SharedString,
|
|
109
113
|
): IEndpointInRangeIndex<SequenceInterval> {
|
|
@@ -15,6 +15,9 @@ import {
|
|
|
15
15
|
import { SharedString } from "../sharedString";
|
|
16
16
|
import { IntervalIndex } from "./intervalIndex";
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
18
21
|
export interface IEndpointIndex<TInterval extends ISerializableInterval>
|
|
19
22
|
extends IntervalIndex<TInterval> {
|
|
20
23
|
/**
|
|
@@ -79,6 +82,9 @@ export class EndpointIndex<TInterval extends ISerializableInterval>
|
|
|
79
82
|
}
|
|
80
83
|
}
|
|
81
84
|
|
|
85
|
+
/**
|
|
86
|
+
* @public
|
|
87
|
+
*/
|
|
82
88
|
export function createEndpointIndex(sharedString: SharedString): IEndpointIndex<SequenceInterval> {
|
|
83
89
|
const client = (sharedString as unknown as { client: Client }).client;
|
|
84
90
|
return new EndpointIndex<SequenceInterval>(client, sequenceIntervalHelpers);
|