document-model 5.1.0-dev.42 → 5.1.0-dev.43
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/dist/src/core/documents.d.ts +1 -0
- package/dist/src/core/documents.d.ts.map +1 -1
- package/dist/src/core/documents.js +47 -0
- package/dist/src/core/documents.js.map +1 -1
- package/dist/src/core/reducer.d.ts.map +1 -1
- package/dist/src/core/reducer.js +1 -0
- package/dist/src/core/reducer.js.map +1 -1
- package/dist/test/document-helpers/calculateUndoSkipNumber.test.d.ts +2 -0
- package/dist/test/document-helpers/calculateUndoSkipNumber.test.d.ts.map +1 -0
- package/dist/test/document-helpers/calculateUndoSkipNumber.test.js +289 -0
- package/dist/test/document-helpers/calculateUndoSkipNumber.test.js.map +1 -0
- package/dist/test/document-helpers/utils.d.ts +6 -0
- package/dist/test/document-helpers/utils.d.ts.map +1 -1
- package/dist/test/document-helpers/utils.js +34 -0
- package/dist/test/document-helpers/utils.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -3,7 +3,13 @@ export type InputOperation = Partial<Omit<Operation, "index" | "skip">> & {
|
|
|
3
3
|
index: number;
|
|
4
4
|
skip: number;
|
|
5
5
|
type?: string;
|
|
6
|
+
value?: string;
|
|
6
7
|
};
|
|
7
8
|
export declare const buildOperation: (input: InputOperation, shuffled?: boolean) => Operation;
|
|
8
9
|
export declare const buildOperations: (inputs: InputOperation[], shuffled?: boolean) => Operation[];
|
|
10
|
+
/**
|
|
11
|
+
* Simulates applying an undo with the given skip value and returns the resulting state.
|
|
12
|
+
* The state is computed by concatenating the 'value' property of remaining operations.
|
|
13
|
+
*/
|
|
14
|
+
export declare function rebuildState(inputOperations: InputOperation[], undoSkip: number): string;
|
|
9
15
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../test/document-helpers/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../test/document-helpers/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAIhD,MAAM,MAAM,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,GAAG,MAAM,CAAC,CAAC,GAAG;IACxE,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,eAAO,MAAM,cAAc,GACzB,OAAO,cAAc,EACrB,kBAAgB,KACf,SAwBF,CAAC;AAEF,eAAO,MAAM,eAAe,GAC1B,QAAQ,cAAc,EAAE,EACxB,kBAAgB,KACf,SAAS,EAAoD,CAAC;AAEjE;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,eAAe,EAAE,cAAc,EAAE,EACjC,QAAQ,EAAE,MAAM,GACf,MAAM,CAkCR"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { garbageCollect, sortOperations } from "document-model/core";
|
|
1
2
|
import { fakeAction } from "../helpers.js";
|
|
2
3
|
export const buildOperation = (input, shuffled = false) => {
|
|
3
4
|
if (shuffled) {
|
|
@@ -24,4 +25,37 @@ export const buildOperation = (input, shuffled = false) => {
|
|
|
24
25
|
};
|
|
25
26
|
};
|
|
26
27
|
export const buildOperations = (inputs, shuffled = false) => inputs.map((i) => buildOperation(i, shuffled));
|
|
28
|
+
/**
|
|
29
|
+
* Simulates applying an undo with the given skip value and returns the resulting state.
|
|
30
|
+
* The state is computed by concatenating the 'value' property of remaining operations.
|
|
31
|
+
*/
|
|
32
|
+
export function rebuildState(inputOperations, undoSkip) {
|
|
33
|
+
// If skip is -1, result is empty state
|
|
34
|
+
if (undoSkip === -1) {
|
|
35
|
+
return "";
|
|
36
|
+
}
|
|
37
|
+
// Create a new NOOP operation with the calculated skip
|
|
38
|
+
// If undoSkip is not -1, we must have at least one operation
|
|
39
|
+
const lastOp = inputOperations[inputOperations.length - 1];
|
|
40
|
+
const nextIndex = lastOp.index + 1;
|
|
41
|
+
const opsWithUndo = [
|
|
42
|
+
...inputOperations,
|
|
43
|
+
{ index: nextIndex, skip: undoSkip, type: "NOOP" },
|
|
44
|
+
];
|
|
45
|
+
// Build full operations and garbage collect
|
|
46
|
+
const operations = buildOperations(opsWithUndo);
|
|
47
|
+
const effectiveOps = garbageCollect(sortOperations(operations));
|
|
48
|
+
// Build state from values of remaining non-NOOP operations
|
|
49
|
+
return effectiveOps
|
|
50
|
+
.map((op) => {
|
|
51
|
+
// Find the original input operation to get its value
|
|
52
|
+
const inputOp = opsWithUndo.find((input) => input.index === op.index && input.skip === op.skip);
|
|
53
|
+
// Only include value if it's not a NOOP
|
|
54
|
+
if (inputOp?.type === "NOOP") {
|
|
55
|
+
return "";
|
|
56
|
+
}
|
|
57
|
+
return inputOp?.value || "";
|
|
58
|
+
})
|
|
59
|
+
.join("");
|
|
60
|
+
}
|
|
27
61
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../test/document-helpers/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../test/document-helpers/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAS3C,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,KAAqB,EACrB,QAAQ,GAAG,KAAK,EACL,EAAE;IACb,IAAI,QAAQ,EAAE,CAA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