@fluidframework/sequence 2.0.0-internal.8.0.0 → 2.0.0-rc.1.0.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 +54 -0
- package/README.md +0 -6
- package/api-extractor-esm.json +4 -0
- package/api-extractor-lint.json +1 -10
- package/api-extractor.json +1 -9
- package/api-report/sequence.api.md +3 -15
- package/dist/defaultMap.d.ts +2 -2
- package/dist/defaultMap.d.ts.map +1 -1
- package/dist/defaultMap.js +10 -5
- package/dist/defaultMap.js.map +1 -1
- package/dist/defaultMapInterfaces.d.ts +3 -2
- package/dist/defaultMapInterfaces.d.ts.map +1 -1
- package/dist/defaultMapInterfaces.js.map +1 -1
- package/dist/intervalCollection.d.ts +3 -43
- package/dist/intervalCollection.d.ts.map +1 -1
- package/dist/intervalCollection.js +62 -50
- package/dist/intervalCollection.js.map +1 -1
- package/dist/intervals/index.d.ts +1 -1
- package/dist/intervals/index.d.ts.map +1 -1
- package/dist/intervals/index.js +2 -1
- package/dist/intervals/index.js.map +1 -1
- package/dist/intervals/intervalUtils.d.ts +12 -2
- package/dist/intervals/intervalUtils.d.ts.map +1 -1
- package/dist/intervals/intervalUtils.js +10 -3
- package/dist/intervals/intervalUtils.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.d.ts.map +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/revertibles.d.ts.map +1 -1
- package/dist/revertibles.js +9 -3
- package/dist/revertibles.js.map +1 -1
- package/dist/sequence-alpha.d.ts +2 -47
- package/dist/sequence-beta.d.ts +0 -29
- package/dist/sequence-public.d.ts +0 -29
- package/dist/sequence-untrimmed.d.ts +5 -48
- package/dist/sequence.d.ts +2 -2
- package/dist/sequence.d.ts.map +1 -1
- package/dist/sequence.js +5 -1
- package/dist/sequence.js.map +1 -1
- package/dist/sharedString.d.ts +1 -14
- package/dist/sharedString.d.ts.map +1 -1
- package/dist/sharedString.js +0 -12
- package/dist/sharedString.js.map +1 -1
- package/lib/{defaultMap.d.ts → defaultMap.d.mts} +3 -3
- package/lib/defaultMap.d.mts.map +1 -0
- package/lib/{defaultMap.js → defaultMap.mjs} +28 -27
- package/lib/defaultMap.mjs.map +1 -0
- package/lib/{defaultMapInterfaces.d.ts → defaultMapInterfaces.d.mts} +4 -3
- package/lib/defaultMapInterfaces.d.mts.map +1 -0
- package/lib/{intervalIndex/intervalIndex.js → defaultMapInterfaces.mjs} +2 -3
- package/lib/defaultMapInterfaces.mjs.map +1 -0
- package/lib/{index.d.ts → index.d.mts} +12 -24
- package/lib/index.d.mts.map +1 -0
- package/lib/index.mjs +16 -0
- package/lib/index.mjs.map +1 -0
- package/lib/{intervalCollection.d.ts → intervalCollection.d.mts} +6 -46
- package/lib/intervalCollection.d.mts.map +1 -0
- package/lib/{intervalCollection.js → intervalCollection.mjs} +176 -179
- package/lib/intervalCollection.mjs.map +1 -0
- package/lib/intervalIndex/{endpointInRangeIndex.d.ts → endpointInRangeIndex.d.mts} +4 -4
- package/lib/intervalIndex/endpointInRangeIndex.d.mts.map +1 -0
- package/lib/intervalIndex/{endpointInRangeIndex.js → endpointInRangeIndex.mjs} +13 -18
- package/lib/intervalIndex/endpointInRangeIndex.mjs.map +1 -0
- package/lib/intervalIndex/{endpointIndex.d.ts → endpointIndex.d.mts} +4 -4
- package/lib/intervalIndex/endpointIndex.d.mts.map +1 -0
- package/lib/intervalIndex/{endpointIndex.js → endpointIndex.mjs} +9 -14
- package/lib/intervalIndex/endpointIndex.mjs.map +1 -0
- package/lib/intervalIndex/{idIntervalIndex.d.ts → idIntervalIndex.d.mts} +3 -3
- package/lib/intervalIndex/idIntervalIndex.d.mts.map +1 -0
- package/lib/intervalIndex/{idIntervalIndex.js → idIntervalIndex.mjs} +5 -9
- package/lib/intervalIndex/idIntervalIndex.mjs.map +1 -0
- package/lib/intervalIndex/{index.d.ts → index.d.mts} +9 -9
- package/lib/intervalIndex/index.d.mts.map +1 -0
- package/lib/intervalIndex/index.mjs +11 -0
- package/lib/intervalIndex/{index.js.map → index.mjs.map} +1 -1
- package/lib/intervalIndex/{intervalIndex.d.ts → intervalIndex.d.mts} +2 -2
- package/lib/intervalIndex/intervalIndex.d.mts.map +1 -0
- package/lib/intervalIndex/intervalIndex.mjs +6 -0
- package/lib/intervalIndex/{intervalIndex.js.map → intervalIndex.mjs.map} +1 -1
- package/lib/intervalIndex/{intervalIndexUtils.d.ts → intervalIndexUtils.d.mts} +1 -1
- package/lib/intervalIndex/intervalIndexUtils.d.mts.map +1 -0
- package/lib/intervalIndex/{intervalIndexUtils.js → intervalIndexUtils.mjs} +5 -9
- package/lib/intervalIndex/intervalIndexUtils.mjs.map +1 -0
- package/lib/intervalIndex/{overlappingIntervalsIndex.d.ts → overlappingIntervalsIndex.d.mts} +6 -6
- package/lib/intervalIndex/overlappingIntervalsIndex.d.mts.map +1 -0
- package/lib/intervalIndex/{overlappingIntervalsIndex.js → overlappingIntervalsIndex.mjs} +11 -16
- package/lib/intervalIndex/overlappingIntervalsIndex.mjs.map +1 -0
- package/lib/intervalIndex/{overlappingSequenceIntervalsIndex.d.ts → overlappingSequenceIntervalsIndex.d.mts} +3 -3
- package/lib/intervalIndex/overlappingSequenceIntervalsIndex.d.mts.map +1 -0
- package/lib/intervalIndex/overlappingSequenceIntervalsIndex.mjs +37 -0
- package/lib/intervalIndex/overlappingSequenceIntervalsIndex.mjs.map +1 -0
- package/lib/intervalIndex/{sequenceIntervalIndexes.d.ts → sequenceIntervalIndexes.d.mts} +3 -3
- package/lib/intervalIndex/sequenceIntervalIndexes.d.mts.map +1 -0
- package/lib/intervalIndex/sequenceIntervalIndexes.mjs +6 -0
- package/lib/intervalIndex/{sequenceIntervalIndexes.js.map → sequenceIntervalIndexes.mjs.map} +1 -1
- package/lib/intervalIndex/{startpointInRangeIndex.d.ts → startpointInRangeIndex.d.mts} +4 -4
- package/lib/intervalIndex/startpointInRangeIndex.d.mts.map +1 -0
- package/lib/intervalIndex/{startpointInRangeIndex.js → startpointInRangeIndex.mjs} +13 -18
- package/lib/intervalIndex/startpointInRangeIndex.mjs.map +1 -0
- package/lib/{intervalTree.d.ts → intervalTree.d.mts} +2 -2
- package/lib/intervalTree.d.mts.map +1 -0
- package/lib/{intervalTree.js → intervalTree.mjs} +4 -8
- package/lib/intervalTree.mjs.map +1 -0
- package/lib/intervals/{index.d.ts → index.d.mts} +4 -4
- package/lib/intervals/index.d.mts.map +1 -0
- package/lib/intervals/index.mjs +8 -0
- package/lib/intervals/index.mjs.map +1 -0
- package/lib/intervals/{interval.d.ts → interval.d.mts} +3 -3
- package/lib/intervals/interval.d.mts.map +1 -0
- package/lib/intervals/{interval.js → interval.mjs} +13 -18
- package/lib/intervals/interval.mjs.map +1 -0
- package/lib/intervals/{intervalUtils.d.ts → intervalUtils.d.mts} +14 -4
- package/lib/intervals/intervalUtils.d.mts.map +1 -0
- package/lib/intervals/{intervalUtils.js → intervalUtils.mjs} +22 -21
- package/lib/intervals/intervalUtils.mjs.map +1 -0
- package/lib/intervals/{sequenceInterval.d.ts → sequenceInterval.d.mts} +3 -3
- package/lib/intervals/sequenceInterval.d.mts.map +1 -0
- package/lib/intervals/{sequenceInterval.js → sequenceInterval.mjs} +56 -64
- package/lib/intervals/sequenceInterval.mjs.map +1 -0
- package/lib/{localValues.d.ts → localValues.d.mts} +3 -3
- package/lib/localValues.d.mts.map +1 -0
- package/lib/{localValues.js → localValues.mjs} +5 -10
- package/lib/localValues.mjs.map +1 -0
- package/lib/{packageVersion.d.ts → packageVersion.d.mts} +2 -2
- package/lib/packageVersion.d.mts.map +1 -0
- package/lib/packageVersion.mjs +9 -0
- package/lib/packageVersion.mjs.map +1 -0
- package/lib/{revertibles.d.ts → revertibles.d.mts} +4 -4
- package/lib/revertibles.d.mts.map +1 -0
- package/lib/{revertibles.js → revertibles.mjs} +71 -74
- package/lib/revertibles.mjs.map +1 -0
- package/lib/{sequence-alpha.d.ts → sequence-alpha.d.mts} +2 -60
- package/lib/{sequence-public.d.ts → sequence-beta.d.mts} +0 -42
- package/lib/{sequence-beta.d.ts → sequence-public.d.mts} +0 -42
- package/lib/{sequence-untrimmed.d.ts → sequence-untrimmed.d.mts} +5 -61
- package/lib/{sequence.d.ts → sequence.d.mts} +7 -7
- package/lib/sequence.d.mts.map +1 -0
- package/lib/{sequence.js → sequence.mjs} +51 -48
- package/lib/sequence.mjs.map +1 -0
- package/lib/{sequenceDeltaEvent.d.ts → sequenceDeltaEvent.d.mts} +1 -1
- package/lib/sequenceDeltaEvent.d.mts.map +1 -0
- package/lib/{sequenceDeltaEvent.js → sequenceDeltaEvent.mjs} +10 -14
- package/lib/sequenceDeltaEvent.mjs.map +1 -0
- package/lib/{sequenceFactory.d.ts → sequenceFactory.d.mts} +2 -2
- package/lib/sequenceFactory.d.mts.map +1 -0
- package/lib/{sequenceFactory.js → sequenceFactory.mjs} +10 -14
- package/lib/sequenceFactory.mjs.map +1 -0
- package/lib/{sharedIntervalCollection.d.ts → sharedIntervalCollection.d.mts} +3 -3
- package/lib/sharedIntervalCollection.d.mts.map +1 -0
- package/lib/{sharedIntervalCollection.js → sharedIntervalCollection.mjs} +14 -19
- package/lib/sharedIntervalCollection.mjs.map +1 -0
- package/lib/{sharedSequence.d.ts → sharedSequence.d.mts} +2 -2
- package/lib/sharedSequence.d.mts.map +1 -0
- package/lib/{sharedSequence.js → sharedSequence.mjs} +7 -12
- package/lib/sharedSequence.mjs.map +1 -0
- package/lib/{sharedString.d.ts → sharedString.d.mts} +4 -17
- package/lib/sharedString.d.mts.map +1 -0
- package/lib/{sharedString.js → sharedString.mjs} +17 -34
- package/lib/sharedString.mjs.map +1 -0
- package/package.json +97 -46
- package/src/defaultMap.ts +17 -12
- package/src/defaultMapInterfaces.ts +9 -2
- package/src/intervalCollection.ts +67 -123
- package/src/intervals/index.ts +1 -0
- package/src/intervals/intervalUtils.ts +14 -4
- package/src/packageVersion.ts +1 -1
- package/src/revertibles.ts +9 -11
- package/src/sequence.ts +7 -3
- package/src/sharedString.ts +0 -23
- package/lib/defaultMap.d.ts.map +0 -1
- package/lib/defaultMap.js.map +0 -1
- package/lib/defaultMapInterfaces.d.ts.map +0 -1
- package/lib/defaultMapInterfaces.js +0 -7
- package/lib/defaultMapInterfaces.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js +0 -60
- package/lib/index.js.map +0 -1
- package/lib/intervalCollection.d.ts.map +0 -1
- package/lib/intervalCollection.js.map +0 -1
- package/lib/intervalIndex/endpointInRangeIndex.d.ts.map +0 -1
- package/lib/intervalIndex/endpointInRangeIndex.js.map +0 -1
- package/lib/intervalIndex/endpointIndex.d.ts.map +0 -1
- package/lib/intervalIndex/endpointIndex.js.map +0 -1
- package/lib/intervalIndex/idIntervalIndex.d.ts.map +0 -1
- package/lib/intervalIndex/idIntervalIndex.js.map +0 -1
- package/lib/intervalIndex/index.d.ts.map +0 -1
- package/lib/intervalIndex/index.js +0 -24
- package/lib/intervalIndex/intervalIndex.d.ts.map +0 -1
- package/lib/intervalIndex/intervalIndexUtils.d.ts.map +0 -1
- package/lib/intervalIndex/intervalIndexUtils.js.map +0 -1
- package/lib/intervalIndex/overlappingIntervalsIndex.d.ts.map +0 -1
- package/lib/intervalIndex/overlappingIntervalsIndex.js.map +0 -1
- package/lib/intervalIndex/overlappingSequenceIntervalsIndex.d.ts.map +0 -1
- package/lib/intervalIndex/overlappingSequenceIntervalsIndex.js +0 -41
- package/lib/intervalIndex/overlappingSequenceIntervalsIndex.js.map +0 -1
- package/lib/intervalIndex/sequenceIntervalIndexes.d.ts.map +0 -1
- package/lib/intervalIndex/sequenceIntervalIndexes.js +0 -7
- package/lib/intervalIndex/startpointInRangeIndex.d.ts.map +0 -1
- package/lib/intervalIndex/startpointInRangeIndex.js.map +0 -1
- package/lib/intervalTree.d.ts.map +0 -1
- package/lib/intervalTree.js.map +0 -1
- package/lib/intervals/index.d.ts.map +0 -1
- package/lib/intervals/index.js +0 -23
- package/lib/intervals/index.js.map +0 -1
- package/lib/intervals/interval.d.ts.map +0 -1
- package/lib/intervals/interval.js.map +0 -1
- package/lib/intervals/intervalUtils.d.ts.map +0 -1
- package/lib/intervals/intervalUtils.js.map +0 -1
- package/lib/intervals/sequenceInterval.d.ts.map +0 -1
- package/lib/intervals/sequenceInterval.js.map +0 -1
- package/lib/localValues.d.ts.map +0 -1
- package/lib/localValues.js.map +0 -1
- package/lib/packageVersion.d.ts.map +0 -1
- package/lib/packageVersion.js +0 -12
- package/lib/packageVersion.js.map +0 -1
- package/lib/revertibles.d.ts.map +0 -1
- package/lib/revertibles.js.map +0 -1
- package/lib/sequence.d.ts.map +0 -1
- package/lib/sequence.js.map +0 -1
- package/lib/sequenceDeltaEvent.d.ts.map +0 -1
- package/lib/sequenceDeltaEvent.js.map +0 -1
- package/lib/sequenceFactory.d.ts.map +0 -1
- package/lib/sequenceFactory.js.map +0 -1
- package/lib/sharedIntervalCollection.d.ts.map +0 -1
- package/lib/sharedIntervalCollection.js.map +0 -1
- package/lib/sharedSequence.d.ts.map +0 -1
- package/lib/sharedSequence.js.map +0 -1
- package/lib/sharedString.d.ts.map +0 -1
- package/lib/sharedString.js.map +0 -1
- package/sequence.test-files.tar +0 -0
- package/tsconfig.esnext.json +0 -6
|
@@ -1,25 +1,21 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/*!
|
|
3
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
3
|
* Licensed under the MIT License.
|
|
5
4
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const shared_object_base_1 = require("@fluidframework/shared-object-base");
|
|
9
|
-
function makeSerializable(localValue, serializer, bind) {
|
|
5
|
+
import { serializeHandles } from "@fluidframework/shared-object-base";
|
|
6
|
+
export function makeSerializable(localValue, serializer, bind) {
|
|
10
7
|
const value = localValue.makeSerialized(serializer, bind);
|
|
11
8
|
return {
|
|
12
9
|
type: value.type,
|
|
13
10
|
value: value.value && JSON.parse(value.value),
|
|
14
11
|
};
|
|
15
12
|
}
|
|
16
|
-
exports.makeSerializable = makeSerializable;
|
|
17
13
|
/**
|
|
18
14
|
* Manages a contained value type.
|
|
19
15
|
*
|
|
20
16
|
* @alpha
|
|
21
17
|
*/
|
|
22
|
-
class ValueTypeLocalValue {
|
|
18
|
+
export class ValueTypeLocalValue {
|
|
23
19
|
/**
|
|
24
20
|
* Create a new ValueTypeLocalValue.
|
|
25
21
|
* @param value - The instance of the value type stored within
|
|
@@ -40,7 +36,7 @@ class ValueTypeLocalValue {
|
|
|
40
36
|
*/
|
|
41
37
|
makeSerialized(serializer, bind) {
|
|
42
38
|
const storedValueType = this.valueType.factory.store(this.value);
|
|
43
|
-
const value =
|
|
39
|
+
const value = serializeHandles(storedValueType, serializer, bind);
|
|
44
40
|
return {
|
|
45
41
|
type: this.type,
|
|
46
42
|
value,
|
|
@@ -59,5 +55,4 @@ class ValueTypeLocalValue {
|
|
|
59
55
|
return handler;
|
|
60
56
|
}
|
|
61
57
|
}
|
|
62
|
-
|
|
63
|
-
//# sourceMappingURL=localValues.js.map
|
|
58
|
+
//# sourceMappingURL=localValues.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localValues.mjs","sourceRoot":"","sources":["../src/localValues.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAGI,EAAoB,gBAAgB,EAAE,MAAM,oCAAoC;AAgCvF,MAAM,UAAU,gBAAgB,CAC/B,UAAuB,EACvB,UAA4B,EAC5B,IAAkB;IAElB,MAAM,KAAK,GAAG,UAAU,CAAC,cAAc,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;IAC1D,OAAO;QACN,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,KAAK,EAAE,KAAK,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC;KAC7C,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,OAAO,mBAAmB;IAC/B;;;;OAIG;IACH,YACiB,KAAQ,EACP,SAAwB;QADzB,UAAK,GAAL,KAAK,CAAG;QACP,cAAS,GAAT,SAAS,CAAe;IACvC,CAAC;IAEJ;;OAEG;IACH,IAAW,IAAI;QACd,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;IAC5B,CAAC;IAED;;OAEG;IACI,cAAc,CAAC,UAA4B,EAAE,IAAkB;QACrE,MAAM,eAAe,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACjE,MAAM,KAAK,GAAG,gBAAgB,CAAC,eAAe,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC;QAElE,OAAO;YACN,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,KAAK;SACL,CAAC;IACH,CAAC;IAED;;;;OAIG;IACI,YAAY,CAAC,MAAsB;QACzC,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAC/C,IAAI,CAAC,OAAO,EAAE;YACb,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;SACxC;QAED,OAAO,OAAO,CAAC;IAChB,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { IFluidSerializer, serializeHandles } from \"@fluidframework/shared-object-base\";\nimport {\n\tISerializableValue,\n\tISerializedValue,\n\tIValueOperation,\n\tIValueType,\n} from \"./defaultMapInterfaces\";\nimport { IntervalOpType } from \"./intervals\";\n\n/**\n * A local value to be stored in a container type DDS.\n */\nexport interface ILocalValue<T = any> {\n\t/**\n\t * Type indicator of the value stored within.\n\t */\n\treadonly type: string;\n\n\t/**\n\t * The in-memory value stored within.\n\t */\n\treadonly value: T;\n\n\t/**\n\t * Retrieve the serialized form of the value stored within.\n\t * @param serializer - Data store runtime's serializer\n\t * @param bind - Container type's handle\n\t * @returns The serialized form of the contained value\n\t */\n\tmakeSerialized(serializer: IFluidSerializer, bind: IFluidHandle): ISerializedValue;\n}\n\nexport function makeSerializable(\n\tlocalValue: ILocalValue,\n\tserializer: IFluidSerializer,\n\tbind: IFluidHandle,\n): ISerializableValue {\n\tconst value = localValue.makeSerialized(serializer, bind);\n\treturn {\n\t\ttype: value.type,\n\t\tvalue: value.value && JSON.parse(value.value),\n\t};\n}\n\n/**\n * Manages a contained value type.\n *\n * @alpha\n */\nexport class ValueTypeLocalValue<T> implements ILocalValue<T> {\n\t/**\n\t * Create a new ValueTypeLocalValue.\n\t * @param value - The instance of the value type stored within\n\t * @param valueType - The type object of the value type stored within\n\t */\n\tconstructor(\n\t\tpublic readonly value: T,\n\t\tprivate readonly valueType: IValueType<T>,\n\t) {}\n\n\t/**\n\t * {@inheritDoc ILocalValue.\"type\"}\n\t */\n\tpublic get type(): string {\n\t\treturn this.valueType.name;\n\t}\n\n\t/**\n\t * {@inheritDoc ILocalValue.makeSerialized}\n\t */\n\tpublic makeSerialized(serializer: IFluidSerializer, bind: IFluidHandle): ISerializedValue {\n\t\tconst storedValueType = this.valueType.factory.store(this.value);\n\t\tconst value = serializeHandles(storedValueType, serializer, bind);\n\n\t\treturn {\n\t\t\ttype: this.type,\n\t\t\tvalue,\n\t\t};\n\t}\n\n\t/**\n\t * Get the handler for a given op of this value type.\n\t * @param opName - The name of the operation that needs processing\n\t * @returns The object which can process the given op\n\t */\n\tpublic getOpHandler(opName: IntervalOpType): IValueOperation<T> {\n\t\tconst handler = this.valueType.ops.get(opName);\n\t\tif (!handler) {\n\t\t\tthrow new Error(\"Unknown type message\");\n\t\t}\n\n\t\treturn handler;\n\t}\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-
|
|
9
|
-
//# sourceMappingURL=packageVersion.d.
|
|
8
|
+
export declare const pkgVersion = "2.0.0-rc.1.0.0";
|
|
9
|
+
//# sourceMappingURL=packageVersion.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"packageVersion.d.mts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,6BAA6B,CAAC;AAClD,eAAO,MAAM,UAAU,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*
|
|
5
|
+
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
|
+
*/
|
|
7
|
+
export const pkgName = "@fluidframework/sequence";
|
|
8
|
+
export const pkgVersion = "2.0.0-rc.1.0.0";
|
|
9
|
+
//# sourceMappingURL=packageVersion.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"packageVersion.mjs","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,0BAA0B,CAAC;AAClD,MAAM,CAAC,MAAM,UAAU,GAAG,gBAAgB,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-rc.1.0.0\";\n"]}
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
import { LocalReferencePosition, MergeTreeDeltaRevertible, PropertySet } from "@fluidframework/merge-tree";
|
|
6
|
-
import { IntervalOpType, SequenceInterval } from "./intervals";
|
|
7
|
-
import { SharedString } from "./sharedString";
|
|
8
|
-
import { SequenceDeltaEvent } from "./sequenceDeltaEvent";
|
|
6
|
+
import { IntervalOpType, SequenceInterval } from "./intervals/index.mjs";
|
|
7
|
+
import { SharedString } from "./sharedString.mjs";
|
|
8
|
+
import { SequenceDeltaEvent } from "./sequenceDeltaEvent.mjs";
|
|
9
9
|
/**
|
|
10
10
|
* Data for undoing edits on SharedStrings and Intervals.
|
|
11
11
|
* @internal
|
|
@@ -83,4 +83,4 @@ export declare function discardSharedStringRevertibles(sharedString: SharedStrin
|
|
|
83
83
|
* @internal
|
|
84
84
|
*/
|
|
85
85
|
export declare function revertSharedStringRevertibles(sharedString: SharedString, revertibles: SharedStringRevertible[]): void;
|
|
86
|
-
//# sourceMappingURL=revertibles.d.
|
|
86
|
+
//# sourceMappingURL=revertibles.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"revertibles.d.mts","sourceRoot":"","sources":["../src/revertibles.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAKI,EAIN,sBAAsB,EAEtB,wBAAwB,EAExB,WAAW,EAQX,MAAM,4BAA4B;OAE5B,EAAE,cAAc,EAAE,gBAAgB,EAAE;OACpC,EAAE,YAAY,EAAuB;OACrC,EAAuB,kBAAkB,EAAE;AAElD;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG,wBAAwB,GAAG,kBAAkB,CAAC;AAInF;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAC3B;IACA,KAAK,EAAE,OAAO,cAAc,CAAC,MAAM,CAAC;IACpC,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,KAAK,EAAE,sBAAsB,CAAC;IAC9B,GAAG,EAAE,sBAAsB,CAAC;CAC3B,GACD;IACA,KAAK,EAAE,OAAO,cAAc,CAAC,GAAG,CAAC;IACjC,QAAQ,EAA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sB,EAAE,4BASrC;AA2CD;;;;GAIG;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;AAmRD;;;GAGG;AACH,wBAAgB,6BAA6B,CAC5C,YAAY,EAAE,YAAY,EAC1B,WAAW,EAAE,sBAAsB,EAAE,QA8BrC"}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/*!
|
|
3
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
3
|
* Licensed under the MIT License.
|
|
5
4
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const intervals_1 = require("./intervals");
|
|
5
|
+
import { assert, unreachableCase } from "@fluidframework/core-utils";
|
|
6
|
+
import { appendToMergeTreeDeltaRevertibles, discardMergeTreeDeltaRevertible, isMergeTreeDeltaRevertible, MergeTreeDeltaType, ReferenceType, refTypeIncludesFlag, revertMergeTreeDeltaRevertibles,
|
|
7
|
+
// eslint-disable-next-line import/no-deprecated
|
|
8
|
+
SortedSet, getSlideToSegoff, SlidingPreference, } from "@fluidframework/merge-tree";
|
|
9
|
+
import { Side } from "./intervalCollection.mjs";
|
|
10
|
+
import { IntervalOpType, SequenceInterval } from "./intervals/index.mjs";
|
|
13
11
|
const idMap = new Map();
|
|
14
12
|
function getUpdatedIdFromInterval(interval) {
|
|
15
13
|
const maybeId = interval.getIntervalId();
|
|
@@ -22,37 +20,36 @@ function getUpdatedId(intervalId) {
|
|
|
22
20
|
* Create revertibles for adding an interval
|
|
23
21
|
* @internal
|
|
24
22
|
*/
|
|
25
|
-
function appendAddIntervalToRevertibles(interval, revertibles) {
|
|
23
|
+
export function appendAddIntervalToRevertibles(interval, revertibles) {
|
|
26
24
|
revertibles.push({
|
|
27
|
-
event:
|
|
25
|
+
event: IntervalOpType.ADD,
|
|
28
26
|
interval,
|
|
29
27
|
});
|
|
30
28
|
return revertibles;
|
|
31
29
|
}
|
|
32
|
-
exports.appendAddIntervalToRevertibles = appendAddIntervalToRevertibles;
|
|
33
30
|
/**
|
|
34
31
|
* Create revertibles for deleting an interval
|
|
35
32
|
* @internal
|
|
36
33
|
*/
|
|
37
|
-
function appendDeleteIntervalToRevertibles(string, interval, revertibles) {
|
|
34
|
+
export function appendDeleteIntervalToRevertibles(string, interval, revertibles) {
|
|
38
35
|
const startSeg = interval.start.getSegment();
|
|
39
36
|
if (!startSeg) {
|
|
40
37
|
return revertibles;
|
|
41
38
|
}
|
|
42
39
|
const startType = startSeg.removedSeq !== undefined
|
|
43
|
-
?
|
|
44
|
-
:
|
|
40
|
+
? ReferenceType.SlideOnRemove | ReferenceType.RangeBegin
|
|
41
|
+
: ReferenceType.StayOnRemove | ReferenceType.RangeBegin;
|
|
45
42
|
const endSeg = interval.end.getSegment();
|
|
46
43
|
if (!endSeg) {
|
|
47
44
|
return revertibles;
|
|
48
45
|
}
|
|
49
46
|
const endType = endSeg.removedSeq !== undefined
|
|
50
|
-
?
|
|
51
|
-
:
|
|
47
|
+
? ReferenceType.SlideOnRemove | ReferenceType.RangeEnd
|
|
48
|
+
: ReferenceType.StayOnRemove | ReferenceType.RangeEnd;
|
|
52
49
|
const startRef = string.createLocalReferencePosition(startSeg, interval.start.getOffset(), startType, undefined, interval.start.slidingPreference);
|
|
53
50
|
const endRef = string.createLocalReferencePosition(endSeg, interval.end.getOffset(), endType, undefined, interval.end.slidingPreference);
|
|
54
51
|
const revertible = {
|
|
55
|
-
event:
|
|
52
|
+
event: IntervalOpType.DELETE,
|
|
56
53
|
interval,
|
|
57
54
|
start: startRef,
|
|
58
55
|
end: endRef,
|
|
@@ -62,27 +59,26 @@ function appendDeleteIntervalToRevertibles(string, interval, revertibles) {
|
|
|
62
59
|
revertibles.push(revertible);
|
|
63
60
|
return revertibles;
|
|
64
61
|
}
|
|
65
|
-
exports.appendDeleteIntervalToRevertibles = appendDeleteIntervalToRevertibles;
|
|
66
62
|
/**
|
|
67
63
|
* Create revertibles for moving endpoints of an interval
|
|
68
64
|
* @internal
|
|
69
65
|
*/
|
|
70
|
-
function appendChangeIntervalToRevertibles(string, newInterval, previousInterval, revertibles) {
|
|
66
|
+
export function appendChangeIntervalToRevertibles(string, newInterval, previousInterval, revertibles) {
|
|
71
67
|
const startSeg = previousInterval.start.getSegment();
|
|
72
68
|
// This logic is needed because the ReferenceType StayOnRemove cannot be used
|
|
73
69
|
// on removed segments. This works for revertibles because the old position of the
|
|
74
70
|
// interval within the removed segment is handled by the remove range revertible.
|
|
75
71
|
const startType = startSeg.removedSeq !== undefined
|
|
76
|
-
?
|
|
77
|
-
:
|
|
72
|
+
? ReferenceType.SlideOnRemove | ReferenceType.RangeBegin
|
|
73
|
+
: ReferenceType.StayOnRemove | ReferenceType.RangeBegin;
|
|
78
74
|
const endSeg = previousInterval.end.getSegment();
|
|
79
75
|
const endType = endSeg.removedSeq !== undefined
|
|
80
|
-
?
|
|
81
|
-
:
|
|
76
|
+
? ReferenceType.SlideOnRemove | ReferenceType.RangeEnd
|
|
77
|
+
: ReferenceType.StayOnRemove | ReferenceType.RangeEnd;
|
|
82
78
|
const prevStartRef = string.createLocalReferencePosition(startSeg, previousInterval.start.getOffset(), startType, undefined, previousInterval.start.slidingPreference);
|
|
83
79
|
const prevEndRef = string.createLocalReferencePosition(endSeg, previousInterval.end.getOffset(), endType, undefined, previousInterval.end.slidingPreference);
|
|
84
80
|
const revertible = {
|
|
85
|
-
event:
|
|
81
|
+
event: IntervalOpType.CHANGE,
|
|
86
82
|
interval: newInterval,
|
|
87
83
|
start: prevStartRef,
|
|
88
84
|
end: prevEndRef,
|
|
@@ -92,31 +88,29 @@ function appendChangeIntervalToRevertibles(string, newInterval, previousInterval
|
|
|
92
88
|
revertibles.push(revertible);
|
|
93
89
|
return revertibles;
|
|
94
90
|
}
|
|
95
|
-
exports.appendChangeIntervalToRevertibles = appendChangeIntervalToRevertibles;
|
|
96
91
|
/**
|
|
97
92
|
* Create revertibles for changing properties of an interval
|
|
98
93
|
* @internal
|
|
99
94
|
*/
|
|
100
|
-
function appendIntervalPropertyChangedToRevertibles(interval, deltas, revertibles) {
|
|
95
|
+
export function appendIntervalPropertyChangedToRevertibles(interval, deltas, revertibles) {
|
|
101
96
|
revertibles.push({
|
|
102
|
-
event:
|
|
97
|
+
event: IntervalOpType.PROPERTY_CHANGED,
|
|
103
98
|
interval,
|
|
104
99
|
propertyDeltas: deltas,
|
|
105
100
|
});
|
|
106
101
|
return revertibles;
|
|
107
102
|
}
|
|
108
|
-
exports.appendIntervalPropertyChangedToRevertibles = appendIntervalPropertyChangedToRevertibles;
|
|
109
103
|
function addIfIntervalEndpoint(ref, segmentLengths, startIntervals, endIntervals) {
|
|
110
|
-
if (
|
|
104
|
+
if (refTypeIncludesFlag(ref.refType, ReferenceType.RangeBegin)) {
|
|
111
105
|
const interval = ref.properties?.interval;
|
|
112
|
-
if (interval && interval instanceof
|
|
106
|
+
if (interval && interval instanceof SequenceInterval) {
|
|
113
107
|
startIntervals.push({ offset: segmentLengths + interval.start.getOffset(), interval });
|
|
114
108
|
return true;
|
|
115
109
|
}
|
|
116
110
|
}
|
|
117
|
-
else if (
|
|
111
|
+
else if (refTypeIncludesFlag(ref.refType, ReferenceType.RangeEnd)) {
|
|
118
112
|
const interval = ref.properties?.interval;
|
|
119
|
-
if (interval && interval instanceof
|
|
113
|
+
if (interval && interval instanceof SequenceInterval) {
|
|
120
114
|
endIntervals.push({ offset: segmentLengths + interval.end.getOffset(), interval });
|
|
121
115
|
return true;
|
|
122
116
|
}
|
|
@@ -129,7 +123,7 @@ function addIfRevertibleRef(ref, segmentLengths, revertibleRefs) {
|
|
|
129
123
|
revertibleRefs.push({
|
|
130
124
|
revertible,
|
|
131
125
|
offset: segmentLengths + ref.getOffset(),
|
|
132
|
-
isStart:
|
|
126
|
+
isStart: refTypeIncludesFlag(ref.refType, ReferenceType.RangeBegin),
|
|
133
127
|
});
|
|
134
128
|
}
|
|
135
129
|
}
|
|
@@ -138,11 +132,11 @@ function addIfRevertibleRef(ref, segmentLengths, revertibleRefs) {
|
|
|
138
132
|
* (e.g. reverting remove of a range that contains an interval will move the interval back)
|
|
139
133
|
* @internal
|
|
140
134
|
*/
|
|
141
|
-
function appendSharedStringDeltaToRevertibles(string, delta, revertibles) {
|
|
135
|
+
export function appendSharedStringDeltaToRevertibles(string, delta, revertibles) {
|
|
142
136
|
if (delta.ranges.length === 0) {
|
|
143
137
|
return;
|
|
144
138
|
}
|
|
145
|
-
if (delta.deltaOperation ===
|
|
139
|
+
if (delta.deltaOperation === MergeTreeDeltaType.REMOVE) {
|
|
146
140
|
const startIntervals = [];
|
|
147
141
|
const endIntervals = [];
|
|
148
142
|
const revertibleRefs = [];
|
|
@@ -160,10 +154,10 @@ function appendSharedStringDeltaToRevertibles(string, delta, revertibles) {
|
|
|
160
154
|
}
|
|
161
155
|
if (startIntervals.length > 0 || endIntervals.length > 0 || revertibleRefs.length > 0) {
|
|
162
156
|
const removeRevertibles = [];
|
|
163
|
-
|
|
164
|
-
|
|
157
|
+
appendToMergeTreeDeltaRevertibles(delta.deltaArgs, removeRevertibles);
|
|
158
|
+
assert(removeRevertibles.length === 1, 0x6c4 /* Remove revertible should be a single delta */);
|
|
165
159
|
const revertible = {
|
|
166
|
-
event:
|
|
160
|
+
event: IntervalOpType.POSITION_REMOVE,
|
|
167
161
|
intervals: [],
|
|
168
162
|
revertibleRefs,
|
|
169
163
|
mergeTreeRevertible: removeRevertibles[0],
|
|
@@ -201,31 +195,29 @@ function appendSharedStringDeltaToRevertibles(string, delta, revertibles) {
|
|
|
201
195
|
// Handle any merge tree delta that is not REMOVE or is REMOVE with no interval endpoints
|
|
202
196
|
const mergeTreeRevertibles = [];
|
|
203
197
|
// Allow merging MergeTreeDeltaRevertible with previous
|
|
204
|
-
if (revertibles.length > 0 &&
|
|
198
|
+
if (revertibles.length > 0 && isMergeTreeDeltaRevertible(revertibles[revertibles.length - 1])) {
|
|
205
199
|
mergeTreeRevertibles.push(revertibles.pop());
|
|
206
200
|
}
|
|
207
|
-
|
|
201
|
+
appendToMergeTreeDeltaRevertibles(delta.deltaArgs, mergeTreeRevertibles);
|
|
208
202
|
revertibles.push(...mergeTreeRevertibles);
|
|
209
203
|
}
|
|
210
|
-
exports.appendSharedStringDeltaToRevertibles = appendSharedStringDeltaToRevertibles;
|
|
211
204
|
/**
|
|
212
205
|
* Clean up resources held by revertibles that are no longer needed.
|
|
213
206
|
* @internal
|
|
214
207
|
*/
|
|
215
|
-
function discardSharedStringRevertibles(sharedString, revertibles) {
|
|
208
|
+
export function discardSharedStringRevertibles(sharedString, revertibles) {
|
|
216
209
|
revertibles.forEach((r) => {
|
|
217
|
-
if (
|
|
218
|
-
|
|
210
|
+
if (isMergeTreeDeltaRevertible(r)) {
|
|
211
|
+
discardMergeTreeDeltaRevertible([r]);
|
|
219
212
|
}
|
|
220
|
-
else if (r.event ===
|
|
213
|
+
else if (r.event === IntervalOpType.CHANGE || r.event === IntervalOpType.DELETE) {
|
|
221
214
|
sharedString.removeLocalReferencePosition(r.start);
|
|
222
215
|
sharedString.removeLocalReferencePosition(r.end);
|
|
223
216
|
}
|
|
224
217
|
});
|
|
225
218
|
}
|
|
226
|
-
exports.discardSharedStringRevertibles = discardSharedStringRevertibles;
|
|
227
219
|
function getSlidePosition(string, lref, pos) {
|
|
228
|
-
const slide =
|
|
220
|
+
const slide = getSlideToSegoff({ segment: lref.getSegment(), offset: undefined }, lref.slidingPreference);
|
|
229
221
|
return slide?.segment !== undefined &&
|
|
230
222
|
slide.offset !== undefined &&
|
|
231
223
|
string.getPosition(slide.segment) !== -1 &&
|
|
@@ -240,8 +232,8 @@ function isValidRange(start, startSlide, end, endSlide, string) {
|
|
|
240
232
|
end < string.getLength() &&
|
|
241
233
|
(start < end ||
|
|
242
234
|
(start === end &&
|
|
243
|
-
(startSlide ===
|
|
244
|
-
endSlide !==
|
|
235
|
+
(startSlide === SlidingPreference.FORWARD ||
|
|
236
|
+
endSlide !== SlidingPreference.FORWARD))));
|
|
245
237
|
}
|
|
246
238
|
function revertLocalAdd(string, revertible) {
|
|
247
239
|
const id = getUpdatedIdFromInterval(revertible.interval);
|
|
@@ -249,17 +241,17 @@ function revertLocalAdd(string, revertible) {
|
|
|
249
241
|
string.getIntervalCollection(label).removeIntervalById(id);
|
|
250
242
|
}
|
|
251
243
|
function createSequencePlace(pos, newSlidingPreference, oldSlidingPreference = undefined) {
|
|
252
|
-
return newSlidingPreference ===
|
|
253
|
-
(newSlidingPreference === undefined && oldSlidingPreference ===
|
|
244
|
+
return newSlidingPreference === SlidingPreference.BACKWARD ||
|
|
245
|
+
(newSlidingPreference === undefined && oldSlidingPreference === SlidingPreference.BACKWARD)
|
|
254
246
|
? {
|
|
255
247
|
pos,
|
|
256
|
-
side:
|
|
248
|
+
side: Side.After,
|
|
257
249
|
}
|
|
258
|
-
: newSlidingPreference ===
|
|
259
|
-
oldSlidingPreference ===
|
|
250
|
+
: newSlidingPreference === SlidingPreference.FORWARD &&
|
|
251
|
+
oldSlidingPreference === SlidingPreference.BACKWARD
|
|
260
252
|
? {
|
|
261
253
|
pos,
|
|
262
|
-
side:
|
|
254
|
+
side: Side.Before,
|
|
263
255
|
}
|
|
264
256
|
: pos; // Avoid setting side if possible since stickiness may not be enabled
|
|
265
257
|
}
|
|
@@ -299,7 +291,10 @@ function revertLocalChange(string, revertible) {
|
|
|
299
291
|
const interval = collection.getIntervalById(id);
|
|
300
292
|
if (interval !== undefined &&
|
|
301
293
|
isValidRange(startSlidePos, revertible.start.slidingPreference ?? interval.start.slidingPreference, endSlidePos, revertible.end.slidingPreference ?? interval.end.slidingPreference, string)) {
|
|
302
|
-
collection.change(id,
|
|
294
|
+
collection.change(id, {
|
|
295
|
+
start: createSequencePlace(startSlidePos, revertible.start.slidingPreference, interval.start.slidingPreference),
|
|
296
|
+
end: createSequencePlace(endSlidePos, revertible.end.slidingPreference, interval.end.slidingPreference),
|
|
297
|
+
});
|
|
303
298
|
}
|
|
304
299
|
string.removeLocalReferencePosition(revertible.start);
|
|
305
300
|
string.removeLocalReferencePosition(revertible.end);
|
|
@@ -308,7 +303,7 @@ function revertLocalPropertyChanged(string, revertible) {
|
|
|
308
303
|
const label = revertible.interval.properties.referenceRangeLabels[0];
|
|
309
304
|
const id = getUpdatedIdFromInterval(revertible.interval);
|
|
310
305
|
const newProps = revertible.propertyDeltas;
|
|
311
|
-
string.getIntervalCollection(label).
|
|
306
|
+
string.getIntervalCollection(label).change(id, { props: newProps });
|
|
312
307
|
}
|
|
313
308
|
function newPosition(offset, restoredRanges) {
|
|
314
309
|
if (offset === undefined) {
|
|
@@ -334,7 +329,7 @@ function newEndpointPosition(offset, restoredRanges, sharedString) {
|
|
|
334
329
|
return pos === undefined ? undefined : sharedString.getPosition(pos.segment) + pos.offset;
|
|
335
330
|
}
|
|
336
331
|
// eslint-disable-next-line import/no-deprecated
|
|
337
|
-
class SortedRangeSet extends
|
|
332
|
+
class SortedRangeSet extends SortedSet {
|
|
338
333
|
getKey(item) {
|
|
339
334
|
return item.ranges[0].segment.ordinal;
|
|
340
335
|
}
|
|
@@ -351,7 +346,7 @@ function revertLocalSequenceRemove(sharedString, revertible) {
|
|
|
351
346
|
}
|
|
352
347
|
};
|
|
353
348
|
sharedString.on("sequenceDelta", saveSegments);
|
|
354
|
-
|
|
349
|
+
revertMergeTreeDeltaRevertibles(sharedString, [revertible.mergeTreeRevertible]);
|
|
355
350
|
sharedString.off("sequenceDelta", saveSegments);
|
|
356
351
|
revertible.intervals.forEach((intervalInfo) => {
|
|
357
352
|
const intervalCollection = sharedString.getIntervalCollection(intervalInfo.label);
|
|
@@ -363,24 +358,27 @@ function revertLocalSequenceRemove(sharedString, revertible) {
|
|
|
363
358
|
const end = newEndpointPosition(intervalInfo.endOffset, restoredRanges, sharedString) ??
|
|
364
359
|
sharedString.localReferencePositionToPosition(interval.end);
|
|
365
360
|
if (isValidRange(start, interval.start.slidingPreference, end, interval.end.slidingPreference, sharedString)) {
|
|
366
|
-
intervalCollection.change(intervalId,
|
|
361
|
+
intervalCollection.change(intervalId, {
|
|
362
|
+
start: createSequencePlace(start, interval.start.slidingPreference),
|
|
363
|
+
end: createSequencePlace(end, interval.end.slidingPreference),
|
|
364
|
+
});
|
|
367
365
|
}
|
|
368
366
|
}
|
|
369
367
|
});
|
|
370
368
|
// fix up the local references used by delete and change revertibles
|
|
371
369
|
revertible.revertibleRefs.forEach((revertibleRef) => {
|
|
372
|
-
|
|
373
|
-
revertibleRef.revertible.event ===
|
|
370
|
+
assert(revertibleRef.revertible.event === IntervalOpType.CHANGE ||
|
|
371
|
+
revertibleRef.revertible.event === IntervalOpType.DELETE, 0x6c5 /* revertible is not delete or change */);
|
|
374
372
|
const pos = newPosition(revertibleRef.offset, restoredRanges);
|
|
375
373
|
if (pos !== undefined) {
|
|
376
374
|
if (revertibleRef.isStart) {
|
|
377
375
|
sharedString.removeLocalReferencePosition(revertibleRef.revertible.start);
|
|
378
|
-
const newRef = sharedString.createLocalReferencePosition(pos.segment, pos.offset,
|
|
376
|
+
const newRef = sharedString.createLocalReferencePosition(pos.segment, pos.offset, ReferenceType.StayOnRemove | ReferenceType.RangeBegin, { revertible: revertibleRef.revertible }, revertibleRef.revertible.start.slidingPreference);
|
|
379
377
|
revertibleRef.revertible.start = newRef;
|
|
380
378
|
}
|
|
381
379
|
else {
|
|
382
380
|
sharedString.removeLocalReferencePosition(revertibleRef.revertible.end);
|
|
383
|
-
const newRef = sharedString.createLocalReferencePosition(pos.segment, pos.offset,
|
|
381
|
+
const newRef = sharedString.createLocalReferencePosition(pos.segment, pos.offset, ReferenceType.StayOnRemove | ReferenceType.RangeEnd, { revertible: revertibleRef.revertible }, revertibleRef.revertible.end.slidingPreference);
|
|
384
382
|
revertibleRef.revertible.end = newRef;
|
|
385
383
|
}
|
|
386
384
|
}
|
|
@@ -390,36 +388,35 @@ function revertLocalSequenceRemove(sharedString, revertible) {
|
|
|
390
388
|
* Invoke revertibles to reverse prior edits
|
|
391
389
|
* @internal
|
|
392
390
|
*/
|
|
393
|
-
function revertSharedStringRevertibles(sharedString, revertibles) {
|
|
391
|
+
export function revertSharedStringRevertibles(sharedString, revertibles) {
|
|
394
392
|
while (revertibles.length > 0) {
|
|
395
393
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
396
394
|
const r = revertibles.pop();
|
|
397
395
|
if ("event" in r) {
|
|
398
396
|
const event = r.event;
|
|
399
397
|
switch (event) {
|
|
400
|
-
case
|
|
398
|
+
case IntervalOpType.ADD:
|
|
401
399
|
revertLocalAdd(sharedString, r);
|
|
402
400
|
break;
|
|
403
|
-
case
|
|
401
|
+
case IntervalOpType.DELETE:
|
|
404
402
|
revertLocalDelete(sharedString, r);
|
|
405
403
|
break;
|
|
406
|
-
case
|
|
404
|
+
case IntervalOpType.CHANGE:
|
|
407
405
|
revertLocalChange(sharedString, r);
|
|
408
406
|
break;
|
|
409
|
-
case
|
|
407
|
+
case IntervalOpType.PROPERTY_CHANGED:
|
|
410
408
|
revertLocalPropertyChanged(sharedString, r);
|
|
411
409
|
break;
|
|
412
|
-
case
|
|
410
|
+
case IntervalOpType.POSITION_REMOVE:
|
|
413
411
|
revertLocalSequenceRemove(sharedString, r);
|
|
414
412
|
break;
|
|
415
413
|
default:
|
|
416
|
-
|
|
414
|
+
unreachableCase(event);
|
|
417
415
|
}
|
|
418
416
|
}
|
|
419
417
|
else {
|
|
420
|
-
|
|
418
|
+
revertMergeTreeDeltaRevertibles(sharedString, [r]);
|
|
421
419
|
}
|
|
422
420
|
}
|
|
423
421
|
}
|
|
424
|
-
|
|
425
|
-
//# sourceMappingURL=revertibles.js.map
|
|
422
|
+
//# sourceMappingURL=revertibles.mjs.map
|
|
@@ -0,0 +1 @@
|
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CAAC,YAAY,GAAG,aAAa,CAAC,QAAQ,EACnD,EAAE,UAAU,EAAE,aAAa,CAAC,UAAU,EAAE,EACxC,aAAa,CAAC,UAAU,CAAC,GAAG,CAAC,iBAAiB,CAC9C,CAAC;gBACF,aAAa,CAAC,UAAU,CAAC,GAAG,GAAG,MAAM,CAAC;aACtC;SACD;IACF,CAAC,CAAC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,6BAA6B,CAC5C,YAA0B,EAC1B,WAAqC;IAErC,OAAO,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE;QAC9B,oEAAoE;QACpE,MAAM,CAAC,GAAG,WAAW,CAAC,GAAG,EAAG,CAAC;QAC7B,IAAI,OAAO,IAAI,CAAC,EAAE;YACjB,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC;YACtB,QAAQ,KAAK,EAAE;gBACd,KAAK,cAAc,CAAC,GAAG;oBACtB,cAAc,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;oBAChC,MAAM;gBACP,KAAK,cAAc,CAAC,MAAM;oBACzB,iBAAiB,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;oBACnC,MAAM;gBACP,KAAK,cAAc,CAAC,MAAM;oBACzB,iBAAiB,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;oBACnC,MAAM;gBACP,KAAK,cAAc,CAAC,gBAAgB;oBACnC,0BAA0B,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;oBAC5C,MAAM;gBACP,KAAK,cAAc,CAAC,eAAe;oBAClC,yBAAyB,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;oBAC3C,MAAM;gBACP;oBACC,eAAe,CAAC,KAAK,CAAC,CAAC;aACxB;SACD;aAAM;YACN,+BAA+B,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;SACnD;KACD;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable no-bitwise */\n\nimport { assert, unreachableCase } from \"@fluidframework/core-utils\";\nimport {\n\tappendToMergeTreeDeltaRevertibles,\n\tdiscardMergeTreeDeltaRevertible,\n\tisMergeTreeDeltaRevertible,\n\tLocalReferencePosition,\n\tMergeTreeDeltaOperationType,\n\tMergeTreeDeltaRevertible,\n\tMergeTreeDeltaType,\n\tPropertySet,\n\tReferenceType,\n\trefTypeIncludesFlag,\n\trevertMergeTreeDeltaRevertibles,\n\t// eslint-disable-next-line import/no-deprecated\n\tSortedSet,\n\tgetSlideToSegoff,\n\tSlidingPreference,\n} from \"@fluidframework/merge-tree\";\nimport { InteriorSequencePlace, Side } from \"./intervalCollection\";\nimport { IntervalOpType, SequenceInterval } from \"./intervals\";\nimport { SharedString, SharedStringSegment } from \"./sharedString\";\nimport { ISequenceDeltaRange, SequenceDeltaEvent } from \"./sequenceDeltaEvent\";\n\n/**\n * Data for undoing edits on SharedStrings and Intervals.\n * @internal\n */\nexport type SharedStringRevertible = MergeTreeDeltaRevertible | IntervalRevertible;\n\nconst idMap = new Map<string, string>();\n\n/**\n * Data for undoing edits affecting Intervals.\n * @internal\n */\nexport type IntervalRevertible =\n\t| {\n\t\t\tevent: typeof IntervalOpType.CHANGE;\n\t\t\tinterval: SequenceInterval;\n\t\t\tstart: LocalReferencePosition;\n\t\t\tend: LocalReferencePosition;\n\t }\n\t| {\n\t\t\tevent: typeof IntervalOpType.ADD;\n\t\t\tinterval: SequenceInterval;\n\t }\n\t| {\n\t\t\tevent: typeof IntervalOpType.DELETE;\n\t\t\tinterval: SequenceInterval;\n\t\t\tstart: LocalReferencePosition;\n\t\t\tend: LocalReferencePosition;\n\t }\n\t| {\n\t\t\tevent: typeof IntervalOpType.PROPERTY_CHANGED;\n\t\t\tinterval: SequenceInterval;\n\t\t\tpropertyDeltas: PropertySet;\n\t }\n\t| {\n\t\t\tevent: typeof IntervalOpType.POSITION_REMOVE;\n\t\t\tintervals: {\n\t\t\t\tintervalId: string;\n\t\t\t\tlabel: string;\n\t\t\t\tstartOffset?: number; // interval start index within a removed range\n\t\t\t\tendOffset?: number; // interval end index within a removed range\n\t\t\t}[];\n\t\t\t// local refs used by IntervalOpType.CHANGE and DELETE revertibles\n\t\t\trevertibleRefs: {\n\t\t\t\trevertible: IntervalRevertible;\n\t\t\t\toffset: number;\n\t\t\t\tisStart: boolean;\n\t\t\t}[];\n\t\t\tmergeTreeRevertible: MergeTreeDeltaRevertible;\n\t };\n\ntype TypedRevertible<T extends IntervalRevertible[\"event\"]> = IntervalRevertible & { event: T };\n\nfunction getUpdatedIdFromInterval(interval: SequenceInterval): string {\n\tconst maybeId = interval.getIntervalId();\n\treturn getUpdatedId(maybeId);\n}\n\nfunction getUpdatedId(intervalId: string): string {\n\treturn idMap.get(intervalId) ?? intervalId;\n}\n\n/**\n * Create revertibles for adding an interval\n * @internal\n */\nexport function appendAddIntervalToRevertibles(\n\tinterval: SequenceInterval,\n\trevertibles: SharedStringRevertible[],\n) {\n\trevertibles.push({\n\t\tevent: IntervalOpType.ADD,\n\t\tinterval,\n\t});\n\n\treturn revertibles;\n}\n\n/**\n * Create revertibles for deleting an interval\n * @internal\n */\nexport function appendDeleteIntervalToRevertibles(\n\tstring: SharedString,\n\tinterval: SequenceInterval,\n\trevertibles: SharedStringRevertible[],\n): SharedStringRevertible[] {\n\tconst startSeg = interval.start.getSegment() as SharedStringSegment | undefined;\n\tif (!startSeg) {\n\t\treturn revertibles;\n\t}\n\tconst startType =\n\t\tstartSeg.removedSeq !== undefined\n\t\t\t? ReferenceType.SlideOnRemove | ReferenceType.RangeBegin\n\t\t\t: ReferenceType.StayOnRemove | ReferenceType.RangeBegin;\n\tconst endSeg = interval.end.getSegment() as SharedStringSegment | undefined;\n\tif (!endSeg) {\n\t\treturn revertibles;\n\t}\n\tconst endType =\n\t\tendSeg.removedSeq !== undefined\n\t\t\t? ReferenceType.SlideOnRemove | ReferenceType.RangeEnd\n\t\t\t: ReferenceType.StayOnRemove | ReferenceType.RangeEnd;\n\tconst startRef = string.createLocalReferencePosition(\n\t\tstartSeg,\n\t\tinterval.start.getOffset(),\n\t\tstartType,\n\t\tundefined,\n\t\tinterval.start.slidingPreference,\n\t);\n\tconst endRef = string.createLocalReferencePosition(\n\t\tendSeg,\n\t\tinterval.end.getOffset(),\n\t\tendType,\n\t\tundefined,\n\t\tinterval.end.slidingPreference,\n\t);\n\tconst revertible = {\n\t\tevent: IntervalOpType.DELETE,\n\t\tinterval,\n\t\tstart: startRef,\n\t\tend: endRef,\n\t};\n\trevertible.start.addProperties({ revertible });\n\trevertible.end.addProperties({ revertible });\n\trevertibles.push(revertible);\n\n\treturn revertibles;\n}\n\n/**\n * Create revertibles for moving endpoints of an interval\n * @internal\n */\nexport function appendChangeIntervalToRevertibles(\n\tstring: SharedString,\n\tnewInterval: SequenceInterval,\n\tpreviousInterval: SequenceInterval,\n\trevertibles: SharedStringRevertible[],\n) {\n\tconst startSeg = previousInterval.start.getSegment() as SharedStringSegment;\n\t// This logic is needed because the ReferenceType StayOnRemove cannot be used\n\t// on removed segments. This works for revertibles because the old position of the\n\t// interval within the removed segment is handled by the remove range revertible.\n\tconst startType =\n\t\tstartSeg.removedSeq !== undefined\n\t\t\t? ReferenceType.SlideOnRemove | ReferenceType.RangeBegin\n\t\t\t: ReferenceType.StayOnRemove | ReferenceType.RangeBegin;\n\tconst endSeg = previousInterval.end.getSegment() as SharedStringSegment;\n\tconst endType =\n\t\tendSeg.removedSeq !== undefined\n\t\t\t? ReferenceType.SlideOnRemove | ReferenceType.RangeEnd\n\t\t\t: ReferenceType.StayOnRemove | ReferenceType.RangeEnd;\n\tconst prevStartRef = string.createLocalReferencePosition(\n\t\tstartSeg,\n\t\tpreviousInterval.start.getOffset(),\n\t\tstartType,\n\t\tundefined,\n\t\tpreviousInterval.start.slidingPreference,\n\t);\n\tconst prevEndRef = string.createLocalReferencePosition(\n\t\tendSeg,\n\t\tpreviousInterval.end.getOffset(),\n\t\tendType,\n\t\tundefined,\n\t\tpreviousInterval.end.slidingPreference,\n\t);\n\tconst revertible = {\n\t\tevent: IntervalOpType.CHANGE,\n\t\tinterval: newInterval,\n\t\tstart: prevStartRef,\n\t\tend: prevEndRef,\n\t};\n\trevertible.start.addProperties({ revertible });\n\trevertible.end.addProperties({ revertible });\n\trevertibles.push(revertible);\n\n\treturn revertibles;\n}\n\n/**\n * Create revertibles for changing properties of an interval\n * @internal\n */\nexport function appendIntervalPropertyChangedToRevertibles(\n\tinterval: SequenceInterval,\n\tdeltas: PropertySet,\n\trevertibles: SharedStringRevertible[],\n) {\n\trevertibles.push({\n\t\tevent: IntervalOpType.PROPERTY_CHANGED,\n\t\tinterval,\n\t\tpropertyDeltas: deltas,\n\t});\n\n\treturn revertibles;\n}\n\nfunction addIfIntervalEndpoint(\n\tref: LocalReferencePosition,\n\tsegmentLengths: number,\n\tstartIntervals: { offset: number; interval: SequenceInterval }[],\n\tendIntervals: { offset: number; interval: SequenceInterval }[],\n) {\n\tif (refTypeIncludesFlag(ref.refType, ReferenceType.RangeBegin)) {\n\t\tconst interval = ref.properties?.interval;\n\t\tif (interval && interval instanceof SequenceInterval) {\n\t\t\tstartIntervals.push({ offset: segmentLengths + interval.start.getOffset(), interval });\n\t\t\treturn true;\n\t\t}\n\t} else if (refTypeIncludesFlag(ref.refType, ReferenceType.RangeEnd)) {\n\t\tconst interval = ref.properties?.interval;\n\t\tif (interval && interval instanceof SequenceInterval) {\n\t\t\tendIntervals.push({ offset: segmentLengths + interval.end.getOffset(), interval });\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n}\n\nfunction addIfRevertibleRef(\n\tref: LocalReferencePosition,\n\tsegmentLengths: number,\n\trevertibleRefs: {\n\t\trevertible: IntervalRevertible;\n\t\toffset: number;\n\t\tisStart: boolean;\n\t}[],\n) {\n\tconst revertible = ref.properties?.revertible;\n\tif (revertible) {\n\t\trevertibleRefs.push({\n\t\t\trevertible,\n\t\t\toffset: segmentLengths + ref.getOffset(),\n\t\t\tisStart: refTypeIncludesFlag(ref.refType, ReferenceType.RangeBegin),\n\t\t});\n\t}\n}\n\n/**\n * Create revertibles for SharedStringDeltas, handling indirectly modified intervals\n * (e.g. reverting remove of a range that contains an interval will move the interval back)\n * @internal\n */\nexport function appendSharedStringDeltaToRevertibles(\n\tstring: SharedString,\n\tdelta: SequenceDeltaEvent,\n\trevertibles: SharedStringRevertible[],\n) {\n\tif (delta.ranges.length === 0) {\n\t\treturn;\n\t}\n\tif (delta.deltaOperation === MergeTreeDeltaType.REMOVE) {\n\t\tconst startIntervals: { offset: number; interval: SequenceInterval }[] = [];\n\t\tconst endIntervals: { offset: number; interval: SequenceInterval }[] = [];\n\t\tconst revertibleRefs: {\n\t\t\trevertible: IntervalRevertible;\n\t\t\toffset: number;\n\t\t\tisStart: boolean;\n\t\t}[] = [];\n\t\tlet segmentLengths = 0;\n\n\t\t// find interval endpoints in each segment\n\t\tfor (const deltaRange of delta.ranges) {\n\t\t\tconst refs = deltaRange.segment.localRefs;\n\t\t\tif (refs !== undefined && deltaRange.position !== -1) {\n\t\t\t\tfor (const ref of refs) {\n\t\t\t\t\taddIfIntervalEndpoint(ref, segmentLengths, startIntervals, endIntervals);\n\t\t\t\t\taddIfRevertibleRef(ref, segmentLengths, revertibleRefs);\n\t\t\t\t}\n\t\t\t}\n\t\t\tsegmentLengths += deltaRange.segment.cachedLength;\n\t\t}\n\n\t\tif (startIntervals.length > 0 || endIntervals.length > 0 || revertibleRefs.length > 0) {\n\t\t\tconst removeRevertibles: MergeTreeDeltaRevertible[] = [];\n\t\t\tappendToMergeTreeDeltaRevertibles(delta.deltaArgs, removeRevertibles);\n\t\t\tassert(\n\t\t\t\tremoveRevertibles.length === 1,\n\t\t\t\t0x6c4 /* Remove revertible should be a single delta */,\n\t\t\t);\n\n\t\t\tconst revertible: TypedRevertible<typeof IntervalOpType.POSITION_REMOVE> = {\n\t\t\t\tevent: IntervalOpType.POSITION_REMOVE,\n\t\t\t\tintervals: [],\n\t\t\t\trevertibleRefs,\n\t\t\t\tmergeTreeRevertible: removeRevertibles[0],\n\t\t\t};\n\n\t\t\t// add an interval for each startInterval, accounting for any corresponding endIntervals\n\t\t\tstartIntervals.forEach(({ interval, offset }) => {\n\t\t\t\t// find any corresponding end for this interval\n\t\t\t\tconst endIntervalIndex = endIntervals.findIndex((end) => {\n\t\t\t\t\treturn end.interval === interval;\n\t\t\t\t});\n\t\t\t\tlet endOffset: number | undefined;\n\t\t\t\tif (endIntervalIndex !== -1) {\n\t\t\t\t\tendOffset = endIntervals[endIntervalIndex].offset;\n\t\t\t\t\tendIntervals.splice(endIntervalIndex, 1);\n\t\t\t\t}\n\n\t\t\t\trevertible.intervals.push({\n\t\t\t\t\tintervalId: interval.getIntervalId(),\n\t\t\t\t\tlabel: interval.properties.referenceRangeLabels[0],\n\t\t\t\t\tstartOffset: offset,\n\t\t\t\t\tendOffset,\n\t\t\t\t});\n\t\t\t});\n\n\t\t\t// add any remaining endIntervals that aren't matched with a startInterval\n\t\t\tendIntervals.forEach(({ interval, offset }) => {\n\t\t\t\trevertible.intervals.push({\n\t\t\t\t\tintervalId: interval.getIntervalId(),\n\t\t\t\t\tlabel: interval.properties.referenceRangeLabels[0],\n\t\t\t\t\tendOffset: offset,\n\t\t\t\t});\n\t\t\t});\n\n\t\t\trevertibles.push(revertible);\n\t\t\treturn;\n\t\t}\n\t}\n\n\t// Handle any merge tree delta that is not REMOVE or is REMOVE with no interval endpoints\n\tconst mergeTreeRevertibles: MergeTreeDeltaRevertible[] = [];\n\t// Allow merging MergeTreeDeltaRevertible with previous\n\tif (revertibles.length > 0 && isMergeTreeDeltaRevertible(revertibles[revertibles.length - 1])) {\n\t\tmergeTreeRevertibles.push(revertibles.pop() as MergeTreeDeltaRevertible);\n\t}\n\tappendToMergeTreeDeltaRevertibles(delta.deltaArgs, mergeTreeRevertibles);\n\trevertibles.push(...mergeTreeRevertibles);\n}\n\n/**\n * Clean up resources held by revertibles that are no longer needed.\n * @internal\n */\nexport function discardSharedStringRevertibles(\n\tsharedString: SharedString,\n\trevertibles: SharedStringRevertible[],\n) {\n\trevertibles.forEach((r) => {\n\t\tif (isMergeTreeDeltaRevertible(r)) {\n\t\t\tdiscardMergeTreeDeltaRevertible([r]);\n\t\t} else if (r.event === IntervalOpType.CHANGE || r.event === IntervalOpType.DELETE) {\n\t\t\tsharedString.removeLocalReferencePosition(r.start);\n\t\t\tsharedString.removeLocalReferencePosition(r.end);\n\t\t}\n\t});\n}\n\nfunction getSlidePosition(string: SharedString, lref: LocalReferencePosition, pos: number): number {\n\tconst slide = getSlideToSegoff(\n\t\t{ segment: lref.getSegment(), offset: undefined },\n\t\tlref.slidingPreference,\n\t);\n\treturn slide?.segment !== undefined &&\n\t\tslide.offset !== undefined &&\n\t\tstring.getPosition(slide.segment) !== -1 &&\n\t\t(pos < 0 || pos >= string.getLength())\n\t\t? string.getPosition(slide.segment) + slide.offset\n\t\t: pos;\n}\n\nfunction isValidRange(\n\tstart: number,\n\tstartSlide: SlidingPreference | undefined,\n\tend: number,\n\tendSlide: SlidingPreference | undefined,\n\tstring: SharedString,\n) {\n\treturn (\n\t\tstart >= 0 &&\n\t\tstart < string.getLength() &&\n\t\tend >= 0 &&\n\t\tend < string.getLength() &&\n\t\t(start < end ||\n\t\t\t(start === end &&\n\t\t\t\t(startSlide === SlidingPreference.FORWARD ||\n\t\t\t\t\tendSlide !== SlidingPreference.FORWARD)))\n\t);\n}\n\nfunction revertLocalAdd(\n\tstring: SharedString,\n\trevertible: TypedRevertible<typeof IntervalOpType.ADD>,\n) {\n\tconst id = getUpdatedIdFromInterval(revertible.interval);\n\tconst label = revertible.interval.properties.referenceRangeLabels[0];\n\tstring.getIntervalCollection(label).removeIntervalById(id);\n}\n\nfunction createSequencePlace(\n\tpos: number,\n\tnewSlidingPreference: SlidingPreference | undefined,\n\toldSlidingPreference: SlidingPreference | undefined = undefined,\n): number | InteriorSequencePlace {\n\treturn newSlidingPreference === SlidingPreference.BACKWARD ||\n\t\t(newSlidingPreference === undefined && oldSlidingPreference === SlidingPreference.BACKWARD)\n\t\t? {\n\t\t\t\tpos,\n\t\t\t\tside: Side.After,\n\t\t }\n\t\t: newSlidingPreference === SlidingPreference.FORWARD &&\n\t\t oldSlidingPreference === SlidingPreference.BACKWARD\n\t\t? {\n\t\t\t\tpos,\n\t\t\t\tside: Side.Before,\n\t\t }\n\t\t: pos; // Avoid setting side if possible since stickiness may not be enabled\n}\n\nfunction revertLocalDelete(\n\tstring: SharedString,\n\trevertible: TypedRevertible<typeof IntervalOpType.DELETE>,\n) {\n\tconst label = revertible.interval.properties.referenceRangeLabels[0];\n\tconst collection = string.getIntervalCollection(label);\n\tconst start = string.localReferencePositionToPosition(revertible.start);\n\tconst startSlidePos = getSlidePosition(string, revertible.start, start);\n\tconst end = string.localReferencePositionToPosition(revertible.end);\n\tconst endSlidePos = getSlidePosition(string, revertible.end, end);\n\t// reusing the id causes eventual consistency bugs, so it is removed here and recreated in add\n\tconst { intervalId, ...props } = revertible.interval.properties;\n\tif (\n\t\tisValidRange(\n\t\t\tstartSlidePos,\n\t\t\trevertible.start.slidingPreference,\n\t\t\tendSlidePos,\n\t\t\trevertible.end.slidingPreference,\n\t\t\tstring,\n\t\t)\n\t) {\n\t\tconst int = collection.add({\n\t\t\tstart: createSequencePlace(startSlidePos, revertible.start.slidingPreference),\n\t\t\tend: createSequencePlace(endSlidePos, revertible.end.slidingPreference),\n\t\t\tprops,\n\t\t});\n\n\t\tidMap.forEach((newId, oldId) => {\n\t\t\tif (intervalId === newId) {\n\t\t\t\tidMap.set(oldId, getUpdatedIdFromInterval(int));\n\t\t\t}\n\t\t});\n\t\tidMap.set(intervalId, int.getIntervalId());\n\t}\n\n\tstring.removeLocalReferencePosition(revertible.start);\n\tstring.removeLocalReferencePosition(revertible.end);\n}\n\nfunction revertLocalChange(\n\tstring: SharedString,\n\trevertible: TypedRevertible<typeof IntervalOpType.CHANGE>,\n) {\n\tconst label = revertible.interval.properties.referenceRangeLabels[0];\n\tconst collection = string.getIntervalCollection(label);\n\tconst id = getUpdatedIdFromInterval(revertible.interval);\n\tconst start = string.localReferencePositionToPosition(revertible.start);\n\tconst startSlidePos = getSlidePosition(string, revertible.start, start);\n\tconst end = string.localReferencePositionToPosition(revertible.end);\n\tconst endSlidePos = getSlidePosition(string, revertible.end, end);\n\tconst interval = collection.getIntervalById(id);\n\tif (\n\t\tinterval !== undefined &&\n\t\tisValidRange(\n\t\t\tstartSlidePos,\n\t\t\trevertible.start.slidingPreference ?? interval.start.slidingPreference,\n\t\t\tendSlidePos,\n\t\t\trevertible.end.slidingPreference ?? interval.end.slidingPreference,\n\t\t\tstring,\n\t\t)\n\t) {\n\t\tcollection.change(id, {\n\t\t\tstart: createSequencePlace(\n\t\t\t\tstartSlidePos,\n\t\t\t\trevertible.start.slidingPreference,\n\t\t\t\tinterval.start.slidingPreference,\n\t\t\t),\n\t\t\tend: createSequencePlace(\n\t\t\t\tendSlidePos,\n\t\t\t\trevertible.end.slidingPreference,\n\t\t\t\tinterval.end.slidingPreference,\n\t\t\t),\n\t\t});\n\t}\n\n\tstring.removeLocalReferencePosition(revertible.start);\n\tstring.removeLocalReferencePosition(revertible.end);\n}\n\nfunction revertLocalPropertyChanged(\n\tstring: SharedString,\n\trevertible: TypedRevertible<typeof IntervalOpType.PROPERTY_CHANGED>,\n) {\n\tconst label = revertible.interval.properties.referenceRangeLabels[0];\n\tconst id = getUpdatedIdFromInterval(revertible.interval);\n\tconst newProps = revertible.propertyDeltas;\n\tstring.getIntervalCollection(label).change(id, { props: newProps });\n}\n\nfunction newPosition(offset: number | undefined, restoredRanges: SortedRangeSet) {\n\tif (offset === undefined) {\n\t\treturn undefined;\n\t}\n\n\tlet offsetFromSegment = offset;\n\tfor (const rangeInfo of restoredRanges.items) {\n\t\tif (offsetFromSegment < rangeInfo.length) {\n\t\t\t// find the segment inside the range\n\t\t\tfor (const range of rangeInfo.ranges) {\n\t\t\t\tif (range.segment.cachedLength > offsetFromSegment) {\n\t\t\t\t\treturn { segment: range.segment, offset: offsetFromSegment };\n\t\t\t\t}\n\t\t\t\toffsetFromSegment -= range.segment.cachedLength;\n\t\t\t}\n\t\t}\n\t\toffsetFromSegment -= rangeInfo.length;\n\t}\n\n\treturn undefined;\n}\n\nfunction newEndpointPosition(\n\toffset: number | undefined,\n\trestoredRanges: SortedRangeSet,\n\tsharedString: SharedString,\n) {\n\tconst pos = newPosition(offset, restoredRanges);\n\treturn pos === undefined ? undefined : sharedString.getPosition(pos.segment) + pos.offset;\n}\n\ninterface RangeInfo {\n\tranges: readonly Readonly<ISequenceDeltaRange<MergeTreeDeltaOperationType>>[];\n\tlength: number;\n}\n\n// eslint-disable-next-line import/no-deprecated\nclass SortedRangeSet extends SortedSet<RangeInfo, string> {\n\tprotected getKey(item: RangeInfo): string {\n\t\treturn item.ranges[0].segment.ordinal;\n\t}\n}\n\nfunction revertLocalSequenceRemove(\n\tsharedString: SharedString,\n\trevertible: TypedRevertible<typeof IntervalOpType.POSITION_REMOVE>,\n) {\n\tconst restoredRanges = new SortedRangeSet();\n\tconst saveSegments = (event: SequenceDeltaEvent) => {\n\t\tif (event.ranges.length > 0) {\n\t\t\tlet length = 0;\n\t\t\tevent.ranges.forEach((range) => {\n\t\t\t\tlength += range.segment.cachedLength;\n\t\t\t});\n\t\t\trestoredRanges.addOrUpdate({ ranges: event.ranges, length });\n\t\t}\n\t};\n\tsharedString.on(\"sequenceDelta\", saveSegments);\n\trevertMergeTreeDeltaRevertibles(sharedString, [revertible.mergeTreeRevertible]);\n\tsharedString.off(\"sequenceDelta\", saveSegments);\n\n\trevertible.intervals.forEach((intervalInfo) => {\n\t\tconst intervalCollection = sharedString.getIntervalCollection(intervalInfo.label);\n\t\tconst intervalId = getUpdatedId(intervalInfo.intervalId);\n\t\tconst interval = intervalCollection.getIntervalById(intervalId);\n\t\tif (interval !== undefined) {\n\t\t\tconst start =\n\t\t\t\tnewEndpointPosition(intervalInfo.startOffset, restoredRanges, sharedString) ??\n\t\t\t\tsharedString.localReferencePositionToPosition(interval.start);\n\t\t\tconst end =\n\t\t\t\tnewEndpointPosition(intervalInfo.endOffset, restoredRanges, sharedString) ??\n\t\t\t\tsharedString.localReferencePositionToPosition(interval.end);\n\t\t\tif (\n\t\t\t\tisValidRange(\n\t\t\t\t\tstart,\n\t\t\t\t\tinterval.start.slidingPreference,\n\t\t\t\t\tend,\n\t\t\t\t\tinterval.end.slidingPreference,\n\t\t\t\t\tsharedString,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tintervalCollection.change(intervalId, {\n\t\t\t\t\tstart: createSequencePlace(start, interval.start.slidingPreference),\n\t\t\t\t\tend: createSequencePlace(end, interval.end.slidingPreference),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t});\n\n\t// fix up the local references used by delete and change revertibles\n\trevertible.revertibleRefs.forEach((revertibleRef) => {\n\t\tassert(\n\t\t\trevertibleRef.revertible.event === IntervalOpType.CHANGE ||\n\t\t\t\trevertibleRef.revertible.event === IntervalOpType.DELETE,\n\t\t\t0x6c5 /* revertible is not delete or change */,\n\t\t);\n\t\tconst pos = newPosition(revertibleRef.offset, restoredRanges);\n\t\tif (pos !== undefined) {\n\t\t\tif (revertibleRef.isStart) {\n\t\t\t\tsharedString.removeLocalReferencePosition(revertibleRef.revertible.start);\n\t\t\t\tconst newRef = sharedString.createLocalReferencePosition(\n\t\t\t\t\tpos.segment as SharedStringSegment,\n\t\t\t\t\tpos.offset,\n\t\t\t\t\tReferenceType.StayOnRemove | ReferenceType.RangeBegin,\n\t\t\t\t\t{ revertible: revertibleRef.revertible },\n\t\t\t\t\trevertibleRef.revertible.start.slidingPreference,\n\t\t\t\t);\n\t\t\t\trevertibleRef.revertible.start = newRef;\n\t\t\t} else {\n\t\t\t\tsharedString.removeLocalReferencePosition(revertibleRef.revertible.end);\n\t\t\t\tconst newRef = sharedString.createLocalReferencePosition(\n\t\t\t\t\tpos.segment as SharedStringSegment,\n\t\t\t\t\tpos.offset,\n\t\t\t\t\tReferenceType.StayOnRemove | ReferenceType.RangeEnd,\n\t\t\t\t\t{ revertible: revertibleRef.revertible },\n\t\t\t\t\trevertibleRef.revertible.end.slidingPreference,\n\t\t\t\t);\n\t\t\t\trevertibleRef.revertible.end = newRef;\n\t\t\t}\n\t\t}\n\t});\n}\n\n/**\n * Invoke revertibles to reverse prior edits\n * @internal\n */\nexport function revertSharedStringRevertibles(\n\tsharedString: SharedString,\n\trevertibles: SharedStringRevertible[],\n) {\n\twhile (revertibles.length > 0) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst r = revertibles.pop()!;\n\t\tif (\"event\" in r) {\n\t\t\tconst event = r.event;\n\t\t\tswitch (event) {\n\t\t\t\tcase IntervalOpType.ADD:\n\t\t\t\t\trevertLocalAdd(sharedString, r);\n\t\t\t\t\tbreak;\n\t\t\t\tcase IntervalOpType.DELETE:\n\t\t\t\t\trevertLocalDelete(sharedString, r);\n\t\t\t\t\tbreak;\n\t\t\t\tcase IntervalOpType.CHANGE:\n\t\t\t\t\trevertLocalChange(sharedString, r);\n\t\t\t\t\tbreak;\n\t\t\t\tcase IntervalOpType.PROPERTY_CHANGED:\n\t\t\t\t\trevertLocalPropertyChanged(sharedString, r);\n\t\t\t\t\tbreak;\n\t\t\t\tcase IntervalOpType.POSITION_REMOVE:\n\t\t\t\t\trevertLocalSequenceRemove(sharedString, r);\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tunreachableCase(event);\n\t\t\t}\n\t\t} else {\n\t\t\trevertMergeTreeDeltaRevertibles(sharedString, [r]);\n\t\t}\n\t}\n}\n"]}
|