@prismicio/types-internal 2.2.0-traverse.alpha-1 → 2.2.0-traverse.alpha-3

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 (122) hide show
  1. package/lib/_internal/utils.d.ts +21 -4
  2. package/lib/_internal/utils.js +11 -0
  3. package/lib/content/Document.d.ts +2194 -13
  4. package/lib/content/Document.js +64 -36
  5. package/lib/content/fields/GroupContent.d.ts +6 -4
  6. package/lib/content/fields/GroupContent.js +13 -9
  7. package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +9 -6
  8. package/lib/content/fields/slices/Slice/CompositeSliceContent.js +61 -17
  9. package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +8 -6
  10. package/lib/content/fields/slices/Slice/SharedSliceContent.js +26 -18
  11. package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +11 -0
  12. package/lib/content/fields/slices/Slice/SimpleSliceContent.js +100 -1
  13. package/lib/content/fields/slices/SliceItem.d.ts +15 -0
  14. package/lib/content/fields/slices/SliceItem.js +15 -1
  15. package/lib/content/fields/slices/SlicesContent.d.ts +4 -3
  16. package/lib/content/fields/slices/SlicesContent.js +125 -60
  17. package/lib/customtypes/CustomType.d.ts +8 -1
  18. package/lib/customtypes/CustomType.js +18 -1
  19. package/lib/customtypes/Section.d.ts +3 -0
  20. package/lib/customtypes/diff/SharedSlice.d.ts +6 -0
  21. package/lib/customtypes/widgets/Widget.d.ts +3 -0
  22. package/lib/customtypes/widgets/slices/CompositeSlice.d.ts +5 -0
  23. package/lib/customtypes/widgets/slices/SharedSlice.d.ts +8 -0
  24. package/lib/customtypes/widgets/slices/SharedSlice.js +3 -0
  25. package/lib/customtypes/widgets/slices/Slices.d.ts +6 -0
  26. package/lib/import/converters/fields/nestable/Image.d.ts +3 -1
  27. package/lib/import/converters/fields/nestable/Image.js +18 -2
  28. package/lib/import/converters/fields/nestable/Nestable.js +2 -0
  29. package/lib/import/converters/fields/nestable/RichText.d.ts +4 -0
  30. package/lib/import/converters/fields/nestable/RichText.js +55 -0
  31. package/lib/import/converters/fields/nestable/index.d.ts +1 -0
  32. package/lib/import/converters/fields/nestable/index.js +1 -0
  33. package/lib/import/validators/fields/ImportField.d.ts +6 -0
  34. package/lib/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.js +1 -1
  35. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.js +1 -1
  36. package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.js +1 -1
  37. package/lib/import/validators/fields/ImportSlices/SharedSlice/utils.d.ts +3 -0
  38. package/lib/import/validators/fields/nestable/Embed.d.ts +3 -0
  39. package/lib/import/validators/fields/nestable/Embed.js +3 -8
  40. package/lib/import/validators/fields/nestable/GeoPoint.js +2 -2
  41. package/lib/import/validators/fields/nestable/Image/default.d.ts +22 -0
  42. package/lib/import/validators/fields/nestable/Image/default.js +19 -0
  43. package/lib/import/validators/fields/nestable/Image/index.d.ts +19 -0
  44. package/lib/import/validators/fields/nestable/Image/index.js +22 -22
  45. package/lib/import/validators/fields/nestable/Image/merge.d.ts +23 -0
  46. package/lib/import/validators/fields/nestable/Image/{Decoder.js → merge.js} +18 -14
  47. package/lib/import/validators/fields/nestable/Image/{Validator.d.ts → validators.d.ts} +4 -2
  48. package/lib/import/validators/fields/nestable/Image/{Validator.js → validators.js} +7 -3
  49. package/lib/import/validators/fields/nestable/ImportRichText/ImportBlock.d.ts +6 -0
  50. package/lib/import/validators/fields/nestable/ImportRichText/ImportBlock.js +25 -0
  51. package/lib/import/validators/fields/nestable/ImportRichText/ImportRichText.d.ts +24 -0
  52. package/lib/import/validators/fields/nestable/ImportRichText/ImportRichText.js +26 -0
  53. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportBlockType.d.ts +6 -0
  54. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportBlockType.js +18 -0
  55. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportEmbedBlock.d.ts +10 -0
  56. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportEmbedBlock.js +11 -0
  57. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.d.ts +8 -0
  58. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.js +11 -0
  59. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportTextBlock.d.ts +70 -0
  60. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportTextBlock.js +43 -0
  61. package/lib/import/validators/fields/nestable/ImportRichText/blocks/Span.d.ts +65 -0
  62. package/lib/import/validators/fields/nestable/ImportRichText/blocks/Span.js +20 -0
  63. package/lib/import/validators/fields/nestable/ImportRichText/blocks/index.d.ts +4 -0
  64. package/lib/import/validators/fields/nestable/ImportRichText/blocks/index.js +7 -0
  65. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/HyperlinkSpan.d.ts +24 -0
  66. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/HyperlinkSpan.js +18 -0
  67. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/SpanLocation.d.ts +5 -0
  68. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/SpanLocation.js +10 -0
  69. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.d.ts +17 -0
  70. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.js +22 -0
  71. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/index.d.ts +2 -0
  72. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/index.js +5 -0
  73. package/lib/import/validators/fields/nestable/ImportRichText/index.d.ts +2 -0
  74. package/lib/import/validators/fields/nestable/ImportRichText/index.js +7 -0
  75. package/lib/import/validators/fields/nestable/Link.d.ts +21 -6
  76. package/lib/import/validators/fields/nestable/Link.js +8 -8
  77. package/lib/import/validators/fields/nestable/Nestable.d.ts +8 -1
  78. package/lib/import/validators/fields/nestable/Nestable.js +5 -1
  79. package/lib/import/validators/fields/nestable/index.d.ts +2 -1
  80. package/lib/import/validators/fields/nestable/index.js +4 -1
  81. package/package.json +1 -1
  82. package/src/_internal/utils.ts +63 -7
  83. package/src/content/Document.ts +106 -47
  84. package/src/content/fields/GroupContent.ts +25 -12
  85. package/src/content/fields/slices/Slice/CompositeSliceContent.ts +91 -22
  86. package/src/content/fields/slices/Slice/SharedSliceContent.ts +42 -26
  87. package/src/content/fields/slices/Slice/SimpleSliceContent.ts +144 -1
  88. package/src/content/fields/slices/SliceItem.ts +39 -3
  89. package/src/content/fields/slices/SlicesContent.ts +172 -67
  90. package/src/customtypes/CustomType.ts +23 -1
  91. package/src/customtypes/widgets/slices/CompositeSlice.ts +6 -0
  92. package/src/customtypes/widgets/slices/SharedSlice.ts +12 -0
  93. package/src/import/converters/fields/nestable/Image.ts +34 -4
  94. package/src/import/converters/fields/nestable/Nestable.ts +3 -0
  95. package/src/import/converters/fields/nestable/RichText.ts +62 -0
  96. package/src/import/converters/fields/nestable/index.ts +1 -0
  97. package/src/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.ts +1 -1
  98. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.ts +1 -1
  99. package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.ts +1 -1
  100. package/src/import/validators/fields/nestable/Embed.ts +4 -17
  101. package/src/import/validators/fields/nestable/GeoPoint.ts +2 -2
  102. package/src/import/validators/fields/nestable/Image/default.ts +25 -0
  103. package/src/import/validators/fields/nestable/Image/index.ts +34 -36
  104. package/src/import/validators/fields/nestable/Image/{Decoder.ts → merge.ts} +23 -20
  105. package/src/import/validators/fields/nestable/Image/{Validator.ts → validators.ts} +9 -2
  106. package/src/import/validators/fields/nestable/ImportRichText/ImportBlock.ts +39 -0
  107. package/src/import/validators/fields/nestable/ImportRichText/ImportRichText.ts +41 -0
  108. package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportBlockType.ts +44 -0
  109. package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportEmbedBlock.ts +13 -0
  110. package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.ts +13 -0
  111. package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportTextBlock.ts +56 -0
  112. package/src/import/validators/fields/nestable/ImportRichText/blocks/Span.ts +44 -0
  113. package/src/import/validators/fields/nestable/ImportRichText/blocks/index.ts +4 -0
  114. package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/HyperlinkSpan.ts +24 -0
  115. package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/SpanLocation.ts +8 -0
  116. package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.ts +26 -0
  117. package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/index.ts +2 -0
  118. package/src/import/validators/fields/nestable/ImportRichText/index.ts +2 -0
  119. package/src/import/validators/fields/nestable/Link.ts +18 -13
  120. package/src/import/validators/fields/nestable/Nestable.ts +6 -1
  121. package/src/import/validators/fields/nestable/index.ts +2 -1
  122. package/lib/import/validators/fields/nestable/Image/Decoder.d.ts +0 -26
@@ -1,5 +1,5 @@
1
1
  import * as t from "io-ts";
2
- import type { ContentPath, TraverseContentFn } from "../../../_internal/utils";
2
+ import { ContentPath, TraverseSliceContentFn, TraverseWidgetContentFn } from "../../../_internal/utils";
3
3
  import { type StaticSlices } from "../../../customtypes";
4
4
  import type { LegacyContentCtx, WithTypes } from "../../LegacyContentCtx";
5
5
  export declare const SlicesContentType = "SliceContentType";
@@ -5095,9 +5095,10 @@ export declare const SlicesContent: t.TypeC<{
5095
5095
  }>>;
5096
5096
  }>;
5097
5097
  export declare type SlicesContent = t.TypeOf<typeof SlicesContent>;
5098
- export declare function traverseSlices({ path, model, content, }: {
5098
+ export declare function traverseSlices({ path, key, model, content, }: {
5099
5099
  path: ContentPath;
5100
+ key: string;
5100
5101
  content: SlicesContent;
5101
5102
  model?: StaticSlices | undefined;
5102
- }): (transform: TraverseContentFn) => SlicesContent;
5103
+ }): (transformWidget: TraverseWidgetContentFn, transformSlice: TraverseSliceContentFn) => SlicesContent | undefined;
5103
5104
  export {};
@@ -5,14 +5,15 @@ const tslib_1 = require("tslib");
5
5
  const fp_ts_1 = require("fp-ts");
6
6
  const function_1 = require("fp-ts/lib/function");
7
7
  const t = (0, tslib_1.__importStar)(require("io-ts"));
8
+ const utils_1 = require("../../../_internal/utils");
8
9
  const customtypes_1 = require("../../../customtypes");
9
- const utils_1 = require("../../utils");
10
- const GroupContent_1 = require("../GroupContent");
10
+ const utils_2 = require("../../utils");
11
11
  const CompositeSliceContent_1 = require("./Slice/CompositeSliceContent");
12
12
  const SharedSliceContent_1 = require("./Slice/SharedSliceContent");
13
+ const SimpleSliceContent_1 = require("./Slice/SimpleSliceContent");
13
14
  const SliceItem_1 = require("./SliceItem");
14
15
  exports.SlicesContentType = "SliceContentType";
15
- const isSlicesContent = (u) => (0, utils_1.hasContentType)(u) && u.__TYPE__ === exports.SlicesContentType;
16
+ const isSlicesContent = (u) => (0, utils_2.hasContentType)(u) && u.__TYPE__ === exports.SlicesContentType;
16
17
  exports.isSlicesContent = isSlicesContent;
17
18
  const SlicesLegacy = (ctx) => {
18
19
  const codec = t.array((0, SliceItem_1.SlicesItemLegacy)(ctx));
@@ -36,66 +37,130 @@ exports.SlicesContent = t.type({
36
37
  __TYPE__: t.literal(exports.SlicesContentType),
37
38
  value: t.array(SliceItem_1.SliceItemContent),
38
39
  });
39
- function traverseSlices({ path, model, content, }) {
40
- return (transform) => {
40
+ function findSliceModel(slicesPath, model, content) {
41
+ var _a, _b;
42
+ const defaultModel = (_b = (_a = model === null || model === void 0 ? void 0 : model.config) === null || _a === void 0 ? void 0 : _a.choices) === null || _b === void 0 ? void 0 : _b[content.name];
43
+ // regular case for shared slices
44
+ const sharedSliceModel = () => {
45
+ if ((0, SliceItem_1.isSharedSliceItemContent)(content)) {
46
+ if (defaultModel && (0, customtypes_1.isStaticSharedSlice)(defaultModel)) {
47
+ const variationDef = defaultModel.variations.find((v) => v.id === content.widget.variation);
48
+ return variationDef
49
+ ? {
50
+ type: "SharedSlice",
51
+ sliceName: defaultModel.id,
52
+ variationId: variationDef.id,
53
+ fields: {
54
+ primary: variationDef.primary || {},
55
+ items: variationDef.items || {},
56
+ },
57
+ }
58
+ : undefined;
59
+ }
60
+ }
61
+ return;
62
+ };
63
+ const migratedSliceModel = () => {
64
+ var _a;
65
+ const legacyContentPath = utils_1.ContentPath.append(utils_1.ContentPath.serialize(slicesPath), content.name);
66
+ const migratedSliceModel = Object.values(((_a = model === null || model === void 0 ? void 0 : model.config) === null || _a === void 0 ? void 0 : _a.choices) || {}).find((sliceModel) => {
67
+ var _a;
68
+ if ((0, customtypes_1.isStaticSharedSlice)(sliceModel)) {
69
+ return !!((_a = sliceModel.legacyPaths) === null || _a === void 0 ? void 0 : _a[legacyContentPath]);
70
+ }
71
+ return false;
72
+ });
73
+ if (!migratedSliceModel)
74
+ return;
75
+ const migratedVariation = migratedSliceModel === null || migratedSliceModel === void 0 ? void 0 : migratedSliceModel.variations.find((v) => { var _a; return v.id === ((_a = migratedSliceModel.legacyPaths) === null || _a === void 0 ? void 0 : _a[legacyContentPath]); });
76
+ if (!migratedVariation)
77
+ return;
78
+ return {
79
+ type: "SharedSlice",
80
+ sliceName: migratedSliceModel.id,
81
+ variationId: migratedVariation.id,
82
+ fields: {
83
+ primary: migratedVariation.primary || {},
84
+ items: migratedVariation.items || {},
85
+ },
86
+ };
87
+ };
88
+ const legacySliceModel = () => {
89
+ if (!defaultModel)
90
+ return;
91
+ if ((0, customtypes_1.isCompositeSlice)(defaultModel)) {
92
+ return {
93
+ type: "Slice",
94
+ fields: {
95
+ "non-repeat": defaultModel["non-repeat"] || {},
96
+ repeat: defaultModel.repeat || {},
97
+ },
98
+ };
99
+ }
100
+ if ((0, customtypes_1.isLegacySlice)(defaultModel)) {
101
+ return defaultModel;
102
+ }
103
+ return;
104
+ };
105
+ return sharedSliceModel() || migratedSliceModel() || legacySliceModel();
106
+ }
107
+ function traverseSlices({ path, key, model, content, }) {
108
+ return (transformWidget, transformSlice) => {
41
109
  const value = content.value.reduce((acc, sliceContent) => {
42
- var _a, _b;
43
- const sliceModel = (_b = (_a = model === null || model === void 0 ? void 0 : model.config) === null || _a === void 0 ? void 0 : _a.choices) === null || _b === void 0 ? void 0 : _b[sliceContent.name];
44
- const slicePath = path.concat({
45
- key: sliceContent.key,
46
- type: sliceContent.widget.__TYPE__,
47
- });
48
- const convertedSliceWidget = (() => {
49
- switch (sliceContent.widget.__TYPE__) {
50
- case "SharedSliceContent":
51
- return (0, SharedSliceContent_1.traverseSharedSliceContent)({
52
- path: slicePath,
53
- sliceName: sliceContent.name,
54
- model: sliceModel && (0, customtypes_1.isStaticSharedSlice)(sliceModel)
55
- ? sliceModel
56
- : undefined,
57
- content: sliceContent.widget,
58
- })(transform);
59
- case "CompositeSliceContent":
60
- return (0, CompositeSliceContent_1.traverseCompositeSliceContent)({
61
- path: slicePath,
62
- sliceName: sliceContent.name,
63
- model: sliceModel && (0, customtypes_1.isCompositeSlice)(sliceModel)
64
- ? sliceModel
65
- : undefined,
66
- content: sliceContent.widget,
67
- })(transform);
68
- case "GroupContentType":
69
- return (0, GroupContent_1.traverseGroupContent)({
70
- path: slicePath,
71
- model: sliceModel &&
72
- (0, customtypes_1.isLegacySlice)(sliceModel) &&
73
- sliceModel.type === "Group"
74
- ? sliceModel
75
- : undefined,
76
- content: sliceContent.widget,
77
- })(transform);
78
- default:
79
- return sliceContent.widget;
80
- }
110
+ const sliceModel = model && findSliceModel(path, model, sliceContent);
111
+ const convertedSlice = (() => {
112
+ if ((0, SliceItem_1.isSharedSliceItemContent)(sliceContent))
113
+ return (0, SharedSliceContent_1.traverseSharedSliceContent)({
114
+ path: path.concat({
115
+ key: sliceContent.key,
116
+ type: "SharedSlice",
117
+ }),
118
+ sliceKey: sliceContent.key,
119
+ sliceName: sliceContent.name,
120
+ model: (sliceModel === null || sliceModel === void 0 ? void 0 : sliceModel.type) === "SharedSlice" ? sliceModel : undefined,
121
+ content: sliceContent,
122
+ })(transformWidget, transformSlice);
123
+ if ((0, SliceItem_1.isCompositeSliceItemContent)(sliceContent))
124
+ return (0, CompositeSliceContent_1.traverseCompositeSliceContent)({
125
+ path: path.concat({
126
+ key: sliceContent.key,
127
+ type: "Slice",
128
+ }),
129
+ sliceKey: sliceContent.key,
130
+ sliceName: sliceContent.name,
131
+ model: (sliceModel === null || sliceModel === void 0 ? void 0 : sliceModel.type) === "Slice" ||
132
+ (sliceModel === null || sliceModel === void 0 ? void 0 : sliceModel.type) === "SharedSlice"
133
+ ? sliceModel
134
+ : undefined,
135
+ content: sliceContent,
136
+ })(transformWidget, transformSlice);
137
+ if ((0, SliceItem_1.isSimpleSliceItemContent)(sliceContent))
138
+ return (0, SimpleSliceContent_1.traverseSimpleSliceContent)({
139
+ path: path.concat({
140
+ key: sliceContent.key,
141
+ type: "LegacySlice",
142
+ }),
143
+ sliceKey: sliceContent.key,
144
+ sliceName: sliceContent.name,
145
+ model: sliceModel && (sliceModel === null || sliceModel === void 0 ? void 0 : sliceModel.type) !== "Slice"
146
+ ? sliceModel
147
+ : undefined,
148
+ content: sliceContent,
149
+ })(transformWidget, transformSlice);
150
+ return;
81
151
  })();
82
- const convertedSlice = transform({
83
- key: sliceContent.key,
84
- apiId: sliceContent.name,
85
- path: slicePath,
86
- model: sliceModel,
87
- content: convertedSliceWidget,
88
- });
89
- const convertedSliceParent = convertedSlice && {
90
- ...sliceContent,
91
- widget: convertedSlice,
92
- };
93
- return convertedSliceParent ? acc.concat(convertedSliceParent) : acc;
152
+ return convertedSlice ? acc.concat(convertedSlice) : acc;
94
153
  }, []);
95
- return {
96
- __TYPE__: content.__TYPE__,
97
- value,
98
- };
154
+ return transformWidget({
155
+ path,
156
+ key,
157
+ apiId: key,
158
+ model,
159
+ content: {
160
+ __TYPE__: content.__TYPE__,
161
+ value,
162
+ },
163
+ });
99
164
  };
100
165
  }
101
166
  exports.traverseSlices = traverseSlices;
@@ -1344,6 +1344,9 @@ export declare const StaticCustomType: t.ExactC<t.IntersectionC<[t.TypeC<{
1344
1344
  })[];
1345
1345
  } & {
1346
1346
  description?: string;
1347
+ legacyPaths?: {
1348
+ [x: string]: string;
1349
+ };
1347
1350
  });
1348
1351
  };
1349
1352
  };
@@ -2395,5 +2398,9 @@ export declare function toStatic(customType: CustomType, sharedSlices: Map<strin
2395
2398
  export declare function validateSlices(customType: CustomType, sharedSlices: Map<string, SharedSlice>): Either<CustomTypeSlicesError, CustomType>;
2396
2399
  export declare function collectWidgets(customType: CustomType, f: (ref: string, widget: DynamicWidget) => DynamicWidget | undefined): CustomType;
2397
2400
  export declare function filterMissingSharedSlices(customType: CustomType, sharedSlices: Map<string, SharedSlice>): CustomType;
2398
- export declare function flattenCustomTypeFields(customType: StaticCustomType): Partial<Record<string, StaticWidget>>;
2401
+ export declare function flattenCustomTypeFields(customType: StaticCustomType): Record<string, StaticWidget>;
2402
+ export declare function collectSharedSlices(customType: {
2403
+ customTypeId: string;
2404
+ fields: Record<string, StaticWidget>;
2405
+ }): Record<string, SharedSlice>;
2399
2406
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.flattenCustomTypeFields = exports.filterMissingSharedSlices = exports.collectWidgets = exports.validateSlices = exports.toStatic = exports.flattenStaticWidgets = exports.flattenWidgets = exports.CustomType = exports.StaticCustomType = exports.CustomTypeFormat = void 0;
3
+ exports.collectSharedSlices = exports.flattenCustomTypeFields = exports.filterMissingSharedSlices = exports.collectWidgets = exports.validateSlices = exports.toStatic = exports.flattenStaticWidgets = exports.flattenWidgets = exports.CustomType = exports.StaticCustomType = exports.CustomTypeFormat = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const Either_1 = require("fp-ts/lib/Either");
6
6
  const t = (0, tslib_1.__importStar)(require("io-ts"));
@@ -147,3 +147,20 @@ function flattenCustomTypeFields(customType) {
147
147
  }), {});
148
148
  }
149
149
  exports.flattenCustomTypeFields = flattenCustomTypeFields;
150
+ function collectSharedSlices(customType) {
151
+ return Object.entries(customType.fields).reduce((acc, [, w]) => {
152
+ var _a;
153
+ if (w.type === "Slices" || w.type === "Choice") {
154
+ return {
155
+ ...acc,
156
+ ...Object.entries(((_a = w.config) === null || _a === void 0 ? void 0 : _a.choices) || {}).reduce((sliceZoneAcc, [sliceKey, sliceModel]) => {
157
+ return sliceModel.type === "SharedSlice"
158
+ ? { ...sliceZoneAcc, [sliceKey]: sliceModel }
159
+ : sliceZoneAcc;
160
+ }, {}),
161
+ };
162
+ }
163
+ return acc;
164
+ }, {});
165
+ }
166
+ exports.collectSharedSlices = collectSharedSlices;
@@ -1328,6 +1328,9 @@ export declare const StaticSection: t.RecordC<t.Type<string, string, unknown>, t
1328
1328
  })[];
1329
1329
  } & {
1330
1330
  description?: string;
1331
+ legacyPaths?: {
1332
+ [x: string]: string;
1333
+ };
1331
1334
  });
1332
1335
  };
1333
1336
  };
@@ -340,6 +340,9 @@ export declare const SliceComparator: {
340
340
  })[];
341
341
  } & {
342
342
  description?: string;
343
+ legacyPaths?: {
344
+ [x: string]: string;
345
+ };
343
346
  }) | undefined, sliceB?: ({
344
347
  id: string;
345
348
  type: "SharedSlice";
@@ -674,5 +677,8 @@ export declare const SliceComparator: {
674
677
  })[];
675
678
  } & {
676
679
  description?: string;
680
+ legacyPaths?: {
681
+ [x: string]: string;
682
+ };
677
683
  }) | undefined): SliceDiff | undefined;
678
684
  };
@@ -1667,6 +1667,9 @@ export declare const StaticWidget: t.UnionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
1667
1667
  })[];
1668
1668
  } & {
1669
1669
  description?: string;
1670
+ legacyPaths?: {
1671
+ [x: string]: string;
1672
+ };
1670
1673
  });
1671
1674
  };
1672
1675
  };
@@ -1,4 +1,5 @@
1
1
  import * as t from "io-ts";
2
+ import type { PickOnly } from "../../../_internal/utils";
2
3
  import type { DynamicSlice, StaticSlice } from "./Slice";
3
4
  export declare const CompositeSliceType = "Slice";
4
5
  export declare const CompositeSliceConfig: t.ExactC<t.PartialC<{
@@ -331,4 +332,8 @@ export declare const CompositeSlice: t.ExactC<t.IntersectionC<[t.TypeC<{
331
332
  }>>;
332
333
  }>]>>;
333
334
  export declare type CompositeSlice = t.TypeOf<typeof CompositeSlice>;
335
+ export declare type CompositeSliceFields = {
336
+ type: "Slice";
337
+ fields: PickOnly<CompositeSlice, "non-repeat" | "repeat">;
338
+ };
334
339
  export declare function isCompositeSlice(slice: DynamicSlice | StaticSlice): slice is CompositeSlice;
@@ -1,4 +1,5 @@
1
1
  import * as t from "io-ts";
2
+ import type { PickOnly } from "../../../_internal/utils";
2
3
  import type { SharedSliceRef } from "./SharedSliceRef";
3
4
  import type { DynamicSlice, StaticSlice } from "./Slice";
4
5
  export declare const Variation: t.ExactC<t.IntersectionC<[t.TypeC<{
@@ -326,6 +327,12 @@ export declare const Variation: t.ExactC<t.IntersectionC<[t.TypeC<{
326
327
  }>]>>]>>;
327
328
  }>]>>;
328
329
  export declare type Variation = t.TypeOf<typeof Variation>;
330
+ export declare type VariationFields = {
331
+ type: "SharedSlice";
332
+ sliceName: string;
333
+ variationId: string;
334
+ fields: PickOnly<Variation, "primary" | "items">;
335
+ };
329
336
  export declare const SharedSliceType = "SharedSlice";
330
337
  export declare const SharedSlice: t.ExactC<t.IntersectionC<[t.TypeC<{
331
338
  id: t.StringC;
@@ -657,6 +664,7 @@ export declare const SharedSlice: t.ExactC<t.IntersectionC<[t.TypeC<{
657
664
  }>]>>>;
658
665
  }>, t.PartialC<{
659
666
  description: t.StringC;
667
+ legacyPaths: t.RecordC<t.StringC, t.StringC>;
660
668
  }>]>>;
661
669
  export declare type SharedSlice = t.TypeOf<typeof SharedSlice>;
662
670
  export declare function isStaticSharedSlice(slice: StaticSlice): slice is SharedSlice;
@@ -23,6 +23,8 @@ exports.Variation = t.exact(t.intersection([
23
23
  }),
24
24
  ]));
25
25
  exports.SharedSliceType = "SharedSlice";
26
+ const LegacyPath = t.string;
27
+ const VariationId = t.string;
26
28
  exports.SharedSlice = t.exact(t.intersection([
27
29
  t.type({
28
30
  id: t.string,
@@ -32,6 +34,7 @@ exports.SharedSlice = t.exact(t.intersection([
32
34
  }),
33
35
  t.partial({
34
36
  description: t.string,
37
+ legacyPaths: t.record(LegacyPath, VariationId),
35
38
  }),
36
39
  ]));
37
40
  function isStaticSharedSlice(slice) {
@@ -1653,6 +1653,9 @@ export declare const StaticSlicesConfig: t.ExactC<t.PartialC<{
1653
1653
  })[];
1654
1654
  } & {
1655
1655
  description?: string;
1656
+ legacyPaths?: {
1657
+ [x: string]: string;
1658
+ };
1656
1659
  }, unknown, unknown>]>>;
1657
1660
  }>>;
1658
1661
  export declare type StaticSlicesConfig = t.TypeOf<typeof StaticSlicesConfig>;
@@ -3328,6 +3331,9 @@ export declare const StaticSlices: t.ExactC<t.IntersectionC<[t.TypeC<{
3328
3331
  })[];
3329
3332
  } & {
3330
3333
  description?: string;
3334
+ legacyPaths?: {
3335
+ [x: string]: string;
3336
+ };
3331
3337
  });
3332
3338
  };
3333
3339
  }, unknown, unknown>;
@@ -1,4 +1,6 @@
1
1
  import type { Asset } from "../../../../common";
2
- import type { ImageContent } from "../../../../content";
2
+ import type { ImageContent, ImageContentView } from "../../../../content";
3
3
  import type { ImportImage } from "../../../validators";
4
+ import type { ImportImageBlock } from "../../../validators/fields/nestable/ImportRichText/blocks";
5
+ export declare const imageBlockConverter: (imageBlock: ImportImageBlock, assets: Record<Asset["id"], Asset | undefined>) => ImageContentView;
4
6
  export declare const imageConverter: (imageField: ImportImage["value"], assets: Record<Asset["id"], Asset | undefined>) => ImageContent | undefined;
@@ -1,10 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.imageConverter = void 0;
3
+ exports.imageConverter = exports.imageBlockConverter = void 0;
4
4
  const common_1 = require("../../../../common");
5
5
  const Objects_1 = require("../../../../utils/Objects");
6
- function convertImage(imageField, image) {
6
+ function convertImage(inputImage, image) {
7
7
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
8
+ // We can do that because anyway all properties being read
9
+ const imageField = {
10
+ ...inputImage,
11
+ edit: "edit" in inputImage
12
+ ? inputImage.edit
13
+ : {
14
+ x: 0,
15
+ y: 0,
16
+ zoom: 1,
17
+ },
18
+ dimensions: "dimensions" in inputImage ? inputImage.dimensions : {},
19
+ };
8
20
  return (0, Objects_1.withOptionals)({
9
21
  origin: {
10
22
  id: image.id,
@@ -41,6 +53,10 @@ function convertThumbnails(imageField, assets) {
41
53
  };
42
54
  }, {});
43
55
  }
56
+ const imageBlockConverter = (imageBlock, assets) => {
57
+ return convertImage(imageBlock, (0, common_1.getAssetOrThrow)(assets)(imageBlock.id));
58
+ };
59
+ exports.imageBlockConverter = imageBlockConverter;
44
60
  // All assets from `imageField` must be present in `assets`
45
61
  // If not then function will throw an error
46
62
  const imageConverter = (imageField, assets) => {
@@ -26,6 +26,8 @@ function convertNestableWidget(field, assets, embeds) {
26
26
  return (0, _1.linkConverter)(field.value, assets);
27
27
  case "Image":
28
28
  return (0, _1.imageConverter)(field.value, assets);
29
+ case "StructuredText":
30
+ return (0, _1.richTextConverter)(field.value, assets, embeds);
29
31
  default:
30
32
  throw new Error(`Unsupported type of nestable converter ${JSON.stringify(field)}`);
31
33
  }
@@ -0,0 +1,4 @@
1
+ import type { Asset, Embed } from "../../../../common";
2
+ import type { RichTextContent } from "../../../../content";
3
+ import type { ImportRichText } from "../../../validators";
4
+ export declare const richTextConverter: (richTextField: ImportRichText["value"], assets: Record<Asset["id"], Asset | undefined>, embeds: Record<string, Embed | undefined>) => RichTextContent | undefined;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.richTextConverter = void 0;
4
+ const content_1 = require("../../../../content");
5
+ const Embed_1 = require("./Embed");
6
+ const Image_1 = require("./Image");
7
+ const Link_1 = require("./Link");
8
+ const richTextBlockConverter = (importBlock, assets, embeds) => {
9
+ var _a, _b, _c;
10
+ if (importBlock.type === "image") {
11
+ return {
12
+ type: importBlock.type,
13
+ data: (0, Image_1.imageBlockConverter)(importBlock, assets),
14
+ };
15
+ }
16
+ else if (importBlock.type === "embed") {
17
+ const embedData = (0, Embed_1.embedConverter)(importBlock.oembed, embeds);
18
+ if (!embedData)
19
+ throw new Error("Failed to convert embed data");
20
+ return {
21
+ type: importBlock.type,
22
+ data: embedData,
23
+ };
24
+ }
25
+ else {
26
+ // Text block
27
+ return {
28
+ type: importBlock.type,
29
+ direction: (_a = importBlock.direction) !== null && _a !== void 0 ? _a : "ltr",
30
+ content: {
31
+ text: importBlock.text,
32
+ spans: (_c = (_b = importBlock.spans) === null || _b === void 0 ? void 0 : _b.map((span) => {
33
+ const linkData = span.type === "hyperlink"
34
+ ? (0, Link_1.linkConverter)(span.data, assets)
35
+ : undefined;
36
+ return {
37
+ type: span.type,
38
+ start: span.start,
39
+ end: span.end,
40
+ data: linkData,
41
+ };
42
+ })) !== null && _c !== void 0 ? _c : [],
43
+ },
44
+ };
45
+ }
46
+ };
47
+ const richTextConverter = (richTextField, assets, embeds) => {
48
+ if (richTextField === null)
49
+ return;
50
+ return {
51
+ __TYPE__: content_1.RichTextContentType,
52
+ value: richTextField.map((block) => richTextBlockConverter(block, assets, embeds)),
53
+ };
54
+ };
55
+ exports.richTextConverter = richTextConverter;
@@ -7,6 +7,7 @@ export * from "./Image";
7
7
  export * from "./Link";
8
8
  export * from "./Nestable";
9
9
  export * from "./Number";
10
+ export * from "./RichText";
10
11
  export * from "./Select";
11
12
  export * from "./Text";
12
13
  export * from "./Timestamp";
@@ -10,6 +10,7 @@ const tslib_1 = require("tslib");
10
10
  (0, tslib_1.__exportStar)(require("./Link"), exports);
11
11
  (0, tslib_1.__exportStar)(require("./Nestable"), exports);
12
12
  (0, tslib_1.__exportStar)(require("./Number"), exports);
13
+ (0, tslib_1.__exportStar)(require("./RichText"), exports);
13
14
  (0, tslib_1.__exportStar)(require("./Select"), exports);
14
15
  (0, tslib_1.__exportStar)(require("./Text"), exports);
15
16
  (0, tslib_1.__exportStar)(require("./Timestamp"), exports);
@@ -50,6 +50,9 @@ export declare const ImportField: {
50
50
  }, {
51
51
  link_type: "Document" | "Web" | "Media";
52
52
  } | undefined, unknown> | import("io-ts").Type<{
53
+ type: "StructuredText";
54
+ value: import("./nestable").ImportBlock[] | null;
55
+ }, unknown[] | undefined, unknown> | import("io-ts").Type<{
53
56
  type: "Number";
54
57
  value: number | null;
55
58
  }, number | undefined, unknown> | import("io-ts").Type<{
@@ -74,6 +77,9 @@ export declare const ImportField: {
74
77
  }> | import("fp-ts/lib/Either").Right<{
75
78
  type: "Number";
76
79
  value: number | null;
80
+ }> | import("fp-ts/lib/Either").Right<{
81
+ type: "StructuredText";
82
+ value: import("./nestable").ImportBlock[] | null;
77
83
  }> | import("fp-ts/lib/Either").Right<{
78
84
  type: "Link";
79
85
  value: ({
@@ -8,7 +8,7 @@ const t = (0, tslib_1.__importStar)(require("io-ts"));
8
8
  const validators_1 = require("../../../../../validators");
9
9
  const function_2 = require("../../../../../validators/function");
10
10
  const fields_1 = require("./fields");
11
- const SharedSliceShape = t.type({
11
+ const SharedSliceShape = t.strict({
12
12
  id: fields_1.OptionalSharedSliceId,
13
13
  slice_type: validators_1.NonEmptyString,
14
14
  name: validators_1.String,
@@ -12,7 +12,7 @@ const utils_1 = require("../utils");
12
12
  * slice_type - the validated slice_type
13
13
  * slice - SharedSlice custom type data matching the slice_type. We return it alongside the validated slice_type, because it is needed to decode the 'variation' field in the SharedSlice (see SharedSliceVariation.ts)
14
14
  */
15
- const SharedSliceTypeShape = t.type({
15
+ const SharedSliceTypeShape = t.strict({
16
16
  slice_type: validators_1.NonEmptyString,
17
17
  slice: customtypes_1.SharedSlice,
18
18
  });
@@ -12,7 +12,7 @@ const utils_1 = require("../utils");
12
12
  * variation - the validated variation of the slice
13
13
  * data - Variation data matching the variation. We return it alongside the validated variation, because it is needed to decode the 'primary' and 'items' fields in the SharedSlice.
14
14
  */
15
- const SharedSliceVariationShape = t.type({
15
+ const SharedSliceVariationShape = t.strict({
16
16
  variation: validators_1.NonEmptyString,
17
17
  data: customtypes_1.Variation,
18
18
  });
@@ -335,5 +335,8 @@ export declare const findSlice: (slices: SharedSliceCustomType[]) => (sliceId: s
335
335
  })[];
336
336
  } & {
337
337
  description?: string;
338
+ legacyPaths?: {
339
+ [x: string]: string;
340
+ };
338
341
  }>;
339
342
  export declare const findSliceVariation: (slice: SharedSliceCustomType) => (variation: string) => E.Either<string, Variation>;
@@ -1,4 +1,7 @@
1
1
  import * as t from "io-ts";
2
+ export declare const ImportEmbedValue: t.ExactC<t.TypeC<{
3
+ embed_url: t.Type<string, string, unknown>;
4
+ }>>;
2
5
  export declare const ImportEmbed: t.Type<{
3
6
  type: "Embed";
4
7
  value: {
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ImportEmbed = void 0;
3
+ exports.ImportEmbed = exports.ImportEmbedValue = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const Either = (0, tslib_1.__importStar)(require("fp-ts/Either"));
6
- const function_1 = require("fp-ts/lib/function");
7
5
  const t = (0, tslib_1.__importStar)(require("io-ts"));
8
6
  const validators_1 = require("../../../../validators");
9
7
  const ImportContent_1 = require("../ImportContent");
@@ -27,10 +25,7 @@ const EmbedUrl = new t.Type("EmbedUrl", (u) => isValidHttpUrl(u), (u, c) => {
27
25
  return t.failure(u, c, "The value must be a valid http/https url");
28
26
  }
29
27
  }, t.identity);
30
- const EmbedProto = t.type({
28
+ exports.ImportEmbedValue = t.strict({
31
29
  embed_url: EmbedUrl,
32
30
  });
33
- const Embed = new t.Type("ImportEmbedValue", (u) => EmbedProto.is(u), (u) => {
34
- return (0, function_1.pipe)(EmbedProto.decode(u), Either.map((parsed) => ({ embed_url: parsed.embed_url })));
35
- }, t.identity);
36
- exports.ImportEmbed = (0, ImportContent_1.ImportContent)("Embed", (0, validators_1.EmptyObjectOrElse)(Embed));
31
+ exports.ImportEmbed = (0, ImportContent_1.ImportContent)("Embed", (0, validators_1.EmptyObjectOrElse)(exports.ImportEmbedValue));