@prismicio/types-internal 1.3.0 → 1.4.1
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/lib/content/fields/GroupContent.d.ts +10 -8
- package/lib/content/fields/nestable/LinkContent.d.ts +10 -8
- package/lib/content/fields/nestable/LinkContent.js +5 -3
- package/lib/content/fields/nestable/NestableContent.d.ts +5 -4
- package/lib/content/fields/slices/SharedSliceContent.d.ts +10 -8
- package/lib/customtypes/diff/Changes.d.ts +17 -0
- package/lib/customtypes/diff/Changes.js +9 -0
- package/lib/customtypes/diff/SharedSlice.d.ts +679 -0
- package/lib/customtypes/diff/SharedSlice.js +55 -0
- package/lib/customtypes/diff/Variation.d.ts +662 -0
- package/lib/customtypes/diff/Variation.js +75 -0
- package/lib/customtypes/diff/index.d.ts +3 -0
- package/lib/customtypes/diff/index.js +6 -0
- package/lib/customtypes/index.d.ts +1 -1
- package/lib/customtypes/index.js +1 -1
- package/lib/documents/widgets/nestable/Link/LinkContent.d.ts +16 -10
- package/package.json +1 -1
- package/src/content/fields/nestable/LinkContent.ts +7 -3
- package/src/customtypes/{comparators → diff}/Changes.ts +0 -0
- package/src/customtypes/{comparators → diff}/SharedSlice.ts +0 -0
- package/src/customtypes/{comparators → diff}/Variation.ts +0 -0
- package/src/customtypes/{comparators → diff}/index.ts +0 -0
- package/src/customtypes/index.ts +1 -1
- package/src/documents/widgets/nestable/Link/LinkContent.ts +1 -1
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SliceComparator = void 0;
|
|
4
|
+
const utils_1 = require("../../utils");
|
|
5
|
+
const Changes_1 = require("./Changes");
|
|
6
|
+
const Variation_1 = require("./Variation");
|
|
7
|
+
function compareSliceMeta(sliceA, sliceB) {
|
|
8
|
+
const zippedSlices = utils_1.Objects.zipObjects(sliceA, sliceB);
|
|
9
|
+
return Object.entries(zippedSlices).reduce((acc, [key, value]) => {
|
|
10
|
+
if (key === `variations`)
|
|
11
|
+
return acc;
|
|
12
|
+
if ((value === null || value === void 0 ? void 0 : value.left) === (value === null || value === void 0 ? void 0 : value.right))
|
|
13
|
+
return acc;
|
|
14
|
+
return { ...acc, [key]: value === null || value === void 0 ? void 0 : value.right };
|
|
15
|
+
}, {});
|
|
16
|
+
}
|
|
17
|
+
exports.SliceComparator = {
|
|
18
|
+
compare(sliceA, sliceB) {
|
|
19
|
+
if (!sliceA && sliceB)
|
|
20
|
+
return {
|
|
21
|
+
op: Changes_1.DiffOperation.Added,
|
|
22
|
+
value: sliceB,
|
|
23
|
+
};
|
|
24
|
+
if (sliceA && !sliceB)
|
|
25
|
+
return {
|
|
26
|
+
op: Changes_1.DiffOperation.Removed,
|
|
27
|
+
};
|
|
28
|
+
const diffMeta = compareSliceMeta(sliceA, sliceB);
|
|
29
|
+
const zippedSlices = utils_1.Objects.zipObjects(sliceA && utils_1.Arrays.toRecord(sliceA.variations, (v) => v.id), sliceB && utils_1.Arrays.toRecord(sliceB.variations, (v) => v.id));
|
|
30
|
+
const diffVariations = Object.entries(zippedSlices).reduce((acc, [variationId, value]) => {
|
|
31
|
+
if (!value)
|
|
32
|
+
return acc;
|
|
33
|
+
const vDiff = Variation_1.VariationComparator.compare(value.left, value.right);
|
|
34
|
+
if (!vDiff)
|
|
35
|
+
return acc;
|
|
36
|
+
return {
|
|
37
|
+
...acc,
|
|
38
|
+
[variationId]: vDiff,
|
|
39
|
+
};
|
|
40
|
+
}, {});
|
|
41
|
+
const diffSlice = {
|
|
42
|
+
...diffMeta,
|
|
43
|
+
...(utils_1.Objects.isNotEmpty(diffVariations)
|
|
44
|
+
? { variations: diffVariations }
|
|
45
|
+
: {}),
|
|
46
|
+
};
|
|
47
|
+
if (utils_1.Objects.isNotEmpty(diffSlice)) {
|
|
48
|
+
return {
|
|
49
|
+
op: Changes_1.DiffOperation.Updated,
|
|
50
|
+
value: diffSlice,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
return undefined;
|
|
54
|
+
},
|
|
55
|
+
};
|