@prismicio/types-internal 1.1.1 → 1.2.0-alpha.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.
Files changed (51) hide show
  1. package/lib/customtypes/Comparators/Changes.d.ts +17 -0
  2. package/lib/customtypes/Comparators/Changes.js +9 -0
  3. package/lib/customtypes/Comparators/SharedSlice.d.ts +679 -0
  4. package/lib/customtypes/Comparators/SharedSlice.js +55 -0
  5. package/lib/customtypes/Comparators/Variation.d.ts +662 -0
  6. package/lib/customtypes/Comparators/Variation.js +75 -0
  7. package/lib/customtypes/Comparators/index.d.ts +3 -0
  8. package/lib/customtypes/Comparators/index.js +6 -0
  9. package/lib/customtypes/CustomType.d.ts +932 -932
  10. package/lib/customtypes/Format.d.ts +4 -0
  11. package/lib/customtypes/Format.js +8 -0
  12. package/lib/customtypes/Section.d.ts +932 -932
  13. package/lib/customtypes/comp/Changes.d.ts +17 -0
  14. package/lib/customtypes/comp/Changes.js +9 -0
  15. package/lib/customtypes/comp/SharedSlice.d.ts +679 -0
  16. package/lib/customtypes/comp/SharedSlice.js +55 -0
  17. package/lib/customtypes/comp/Variation.d.ts +662 -0
  18. package/lib/customtypes/comp/Variation.js +76 -0
  19. package/lib/customtypes/comp/index.d.ts +3 -0
  20. package/lib/customtypes/comp/index.js +6 -0
  21. package/lib/customtypes/index.d.ts +1 -0
  22. package/lib/customtypes/index.js +2 -1
  23. package/lib/customtypes/utils/Comparator.d.ts +1353 -0
  24. package/lib/customtypes/utils/Comparator.js +59 -0
  25. package/lib/customtypes/utils/index.d.ts +1 -0
  26. package/lib/customtypes/utils/index.js +4 -0
  27. package/lib/customtypes/widgets/Widget.d.ts +664 -664
  28. package/lib/customtypes/widgets/slices/Slices.d.ts +792 -792
  29. package/lib/documents/widgets/nestable/EmbedContent.d.ts +4 -4
  30. package/lib/documents/widgets/nestable/ImageContent.d.ts +14 -14
  31. package/lib/documents/widgets/nestable/Link/ExternalLink.d.ts +4 -4
  32. package/lib/documents/widgets/nestable/Link/LinkContent.d.ts +2 -2
  33. package/lib/documents/widgets/nestable/Link/index.d.ts +4 -4
  34. package/lib/documents/widgets/nestable/StructuredTextContent/Block.d.ts +8 -8
  35. package/lib/utils/Arrays.d.ts +1 -0
  36. package/lib/utils/Arrays.js +13 -0
  37. package/lib/utils/Objects.d.ts +5 -0
  38. package/lib/utils/Objects.js +21 -0
  39. package/lib/utils/index.d.ts +2 -0
  40. package/lib/utils/index.js +6 -0
  41. package/package.json +2 -2
  42. package/src/customtypes/comparators/Changes.ts +21 -0
  43. package/src/customtypes/comparators/SharedSlice.ts +77 -0
  44. package/src/customtypes/comparators/Variation.ts +101 -0
  45. package/src/customtypes/comparators/index.ts +3 -0
  46. package/src/customtypes/index.ts +1 -0
  47. package/src/documents/widgets/index.ts +4 -2
  48. package/src/utils/Arrays.ts +12 -0
  49. package/src/utils/Objects.ts +24 -0
  50. package/src/utils/index.ts +2 -0
  51. package/CHANGELOG.md +0 -13
@@ -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
+ };