@prismicio/types-internal 3.16.0 → 3.16.1-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.
- package/lib/content/fields/RepeatableContent.d.ts +51 -123
- package/lib/content/fields/RepeatableContent.js +10 -14
- package/lib/content/fields/nestable/RichTextContent/Block.d.ts +1036 -0
- package/lib/content/fields/nestable/RichTextContent/Block.js +31 -0
- package/lib/content/fields/nestable/RichTextContent/EmbedBlock.d.ts +60 -0
- package/lib/content/fields/nestable/RichTextContent/EmbedBlock.js +53 -0
- package/lib/content/fields/nestable/RichTextContent/ImageBlock.d.ts +203 -0
- package/lib/content/fields/nestable/RichTextContent/ImageBlock.js +36 -0
- package/lib/content/fields/nestable/RichTextContent/TableBlock.d.ts +500 -0
- package/lib/content/fields/nestable/RichTextContent/TableBlock.js +21 -0
- package/lib/content/fields/nestable/RichTextContent/TextBlock.d.ts +590 -0
- package/lib/content/fields/nestable/RichTextContent/TextBlock.js +80 -0
- package/lib/scripts/release.d.ts +1 -0
- package/lib/scripts/release.js +34 -0
- package/lib/src/_internal/utils.d.ts +36 -0
- package/lib/src/_internal/utils.js +20 -0
- package/lib/src/common/Asset.d.ts +16 -0
- package/lib/src/common/Asset.js +11 -0
- package/lib/src/common/Embed.d.ts +15 -0
- package/lib/src/common/Embed.js +10 -0
- package/lib/src/common/HexaColorCode.d.ts +4 -0
- package/lib/src/common/HexaColorCode.js +7 -0
- package/lib/src/common/UUID.d.ts +6 -0
- package/lib/src/common/UUID.js +8 -0
- package/lib/src/common/WidgetKey.d.ts +3 -0
- package/lib/src/common/WidgetKey.js +8 -0
- package/lib/src/common/index.d.ts +3 -0
- package/lib/src/common/index.js +6 -0
- package/lib/src/content/Document.d.ts +11803 -0
- package/lib/src/content/Document.js +266 -0
- package/lib/src/content/LegacyContentCtx.d.ts +64 -0
- package/lib/src/content/LegacyContentCtx.js +130 -0
- package/lib/src/content/fields/EmptyContent.d.ts +16 -0
- package/lib/src/content/fields/EmptyContent.js +30 -0
- package/lib/src/content/fields/GroupContent.d.ts +42 -0
- package/lib/src/content/fields/GroupContent.js +208 -0
- package/lib/src/content/fields/UIDContent.d.ts +16 -0
- package/lib/src/content/fields/UIDContent.js +25 -0
- package/lib/src/content/fields/WidgetContent.d.ts +11749 -0
- package/lib/src/content/fields/WidgetContent.js +57 -0
- package/lib/src/content/fields/index.d.ts +6 -0
- package/lib/src/content/fields/index.js +9 -0
- package/lib/src/content/fields/nestable/BooleanContent.d.ts +18 -0
- package/lib/src/content/fields/nestable/BooleanContent.js +35 -0
- package/lib/src/content/fields/nestable/EmbedContent.d.ts +78 -0
- package/lib/src/content/fields/nestable/EmbedContent.js +56 -0
- package/lib/src/content/fields/nestable/FieldContent/ColorContent.d.ts +18 -0
- package/lib/src/content/fields/nestable/FieldContent/ColorContent.js +35 -0
- package/lib/src/content/fields/nestable/FieldContent/DateContent.d.ts +18 -0
- package/lib/src/content/fields/nestable/FieldContent/DateContent.js +35 -0
- package/lib/src/content/fields/nestable/FieldContent/NumberContent.d.ts +18 -0
- package/lib/src/content/fields/nestable/FieldContent/NumberContent.js +35 -0
- package/lib/src/content/fields/nestable/FieldContent/RangeContent.d.ts +18 -0
- package/lib/src/content/fields/nestable/FieldContent/RangeContent.js +35 -0
- package/lib/src/content/fields/nestable/FieldContent/SelectContent.d.ts +20 -0
- package/lib/src/content/fields/nestable/FieldContent/SelectContent.js +46 -0
- package/lib/src/content/fields/nestable/FieldContent/TextContent.d.ts +18 -0
- package/lib/src/content/fields/nestable/FieldContent/TextContent.js +35 -0
- package/lib/src/content/fields/nestable/FieldContent/TimestampContent.d.ts +18 -0
- package/lib/src/content/fields/nestable/FieldContent/TimestampContent.js +35 -0
- package/lib/src/content/fields/nestable/FieldContent/common.d.ts +1 -0
- package/lib/src/content/fields/nestable/FieldContent/common.js +4 -0
- package/lib/src/content/fields/nestable/FieldContent/index.d.ts +49 -0
- package/lib/src/content/fields/nestable/FieldContent/index.js +38 -0
- package/lib/src/content/fields/nestable/GeoPointContent.d.ts +33 -0
- package/lib/src/content/fields/nestable/GeoPointContent.js +31 -0
- package/lib/src/content/fields/nestable/ImageContent.d.ts +227 -0
- package/lib/src/content/fields/nestable/ImageContent.js +73 -0
- package/lib/src/content/fields/nestable/IntegrationFieldContent.d.ts +16 -0
- package/lib/src/content/fields/nestable/IntegrationFieldContent.js +28 -0
- package/lib/src/content/fields/nestable/LinkContent.d.ts +919 -0
- package/lib/src/content/fields/nestable/LinkContent.js +399 -0
- package/lib/src/content/fields/nestable/NestableContent.d.ts +1953 -0
- package/lib/src/content/fields/nestable/NestableContent.js +167 -0
- package/lib/src/content/fields/nestable/RepeatableContent.d.ts +176 -0
- package/lib/src/content/fields/nestable/RepeatableContent.js +104 -0
- package/lib/src/content/fields/nestable/RichTextContent/Blocks.d.ts +1261 -0
- package/lib/src/content/fields/nestable/RichTextContent/Blocks.js +170 -0
- package/lib/src/content/fields/nestable/RichTextContent/index.d.ts +1004 -0
- package/lib/src/content/fields/nestable/RichTextContent/index.js +28 -0
- package/lib/src/content/fields/nestable/SeparatorContent.d.ts +13 -0
- package/lib/src/content/fields/nestable/SeparatorContent.js +22 -0
- package/lib/src/content/fields/nestable/TableContent.d.ts +770 -0
- package/lib/src/content/fields/nestable/TableContent.js +121 -0
- package/lib/src/content/fields/nestable/index.d.ts +12 -0
- package/lib/src/content/fields/nestable/index.js +15 -0
- package/lib/src/content/fields/slices/Slice/CompositeSliceContent.d.ts +3934 -0
- package/lib/src/content/fields/slices/Slice/CompositeSliceContent.js +195 -0
- package/lib/src/content/fields/slices/Slice/RepeatableContent.d.ts +774 -0
- package/lib/src/content/fields/slices/Slice/RepeatableContent.js +21 -0
- package/lib/src/content/fields/slices/Slice/SharedSliceContent.d.ts +3937 -0
- package/lib/src/content/fields/slices/Slice/SharedSliceContent.js +215 -0
- package/lib/src/content/fields/slices/Slice/SimpleSliceContent.d.ts +1962 -0
- package/lib/src/content/fields/slices/Slice/SimpleSliceContent.js +130 -0
- package/lib/src/content/fields/slices/Slice/SlicePrimaryContent.d.ts +1952 -0
- package/lib/src/content/fields/slices/Slice/SlicePrimaryContent.js +30 -0
- package/lib/src/content/fields/slices/Slice/index.d.ts +6810 -0
- package/lib/src/content/fields/slices/Slice/index.js +45 -0
- package/lib/src/content/fields/slices/SliceItem.d.ts +6846 -0
- package/lib/src/content/fields/slices/SliceItem.js +116 -0
- package/lib/src/content/fields/slices/SlicesContent.d.ts +9809 -0
- package/lib/src/content/fields/slices/SlicesContent.js +187 -0
- package/lib/src/content/fields/slices/index.d.ts +3 -0
- package/lib/src/content/fields/slices/index.js +6 -0
- package/lib/src/content/fields/withDefaultValues.d.ts +9 -0
- package/lib/src/content/fields/withDefaultValues.js +79 -0
- package/lib/src/content/index.d.ts +3 -0
- package/lib/src/content/index.js +6 -0
- package/lib/src/content/utils.d.ts +14 -0
- package/lib/src/content/utils.js +33 -0
- package/lib/src/customtypes/CustomType.d.ts +3680 -0
- package/lib/src/customtypes/CustomType.js +184 -0
- package/lib/src/customtypes/Section.d.ts +3635 -0
- package/lib/src/customtypes/Section.js +66 -0
- package/lib/src/customtypes/diff/Changes.d.ts +17 -0
- package/lib/src/customtypes/diff/Changes.js +9 -0
- package/lib/src/customtypes/diff/SharedSlice.d.ts +1624 -0
- package/lib/src/customtypes/diff/SharedSlice.js +55 -0
- package/lib/src/customtypes/diff/Variation.d.ts +1605 -0
- package/lib/src/customtypes/diff/Variation.js +113 -0
- package/lib/src/customtypes/diff/Widgets.d.ts +11 -0
- package/lib/src/customtypes/diff/Widgets.js +2 -0
- package/lib/src/customtypes/diff/index.d.ts +4 -0
- package/lib/src/customtypes/diff/index.js +7 -0
- package/lib/src/customtypes/index.d.ts +4 -0
- package/lib/src/customtypes/index.js +7 -0
- package/lib/src/customtypes/widgets/Group.d.ts +1352 -0
- package/lib/src/customtypes/widgets/Group.js +92 -0
- package/lib/src/customtypes/widgets/UID.d.ts +19 -0
- package/lib/src/customtypes/widgets/UID.js +21 -0
- package/lib/src/customtypes/widgets/Widget.d.ts +4457 -0
- package/lib/src/customtypes/widgets/Widget.js +49 -0
- package/lib/src/customtypes/widgets/index.d.ts +6 -0
- package/lib/src/customtypes/widgets/index.js +9 -0
- package/lib/src/customtypes/widgets/nestable/BooleanField.d.ts +20 -0
- package/lib/src/customtypes/widgets/nestable/BooleanField.js +21 -0
- package/lib/src/customtypes/widgets/nestable/Color.d.ts +17 -0
- package/lib/src/customtypes/widgets/nestable/Color.js +20 -0
- package/lib/src/customtypes/widgets/nestable/Date.d.ts +19 -0
- package/lib/src/customtypes/widgets/nestable/Date.js +21 -0
- package/lib/src/customtypes/widgets/nestable/Embed.d.ts +19 -0
- package/lib/src/customtypes/widgets/nestable/Embed.js +21 -0
- package/lib/src/customtypes/widgets/nestable/GeoPoint.d.ts +15 -0
- package/lib/src/customtypes/widgets/nestable/GeoPoint.js +19 -0
- package/lib/src/customtypes/widgets/nestable/Image.d.ts +44 -0
- package/lib/src/customtypes/widgets/nestable/Image.js +29 -0
- package/lib/src/customtypes/widgets/nestable/IntegrationField.d.ts +19 -0
- package/lib/src/customtypes/widgets/nestable/IntegrationField.js +21 -0
- package/lib/src/customtypes/widgets/nestable/Link.d.ts +196 -0
- package/lib/src/customtypes/widgets/nestable/Link.js +167 -0
- package/lib/src/customtypes/widgets/nestable/NestableWidget.d.ts +217 -0
- package/lib/src/customtypes/widgets/nestable/NestableWidget.js +39 -0
- package/lib/src/customtypes/widgets/nestable/Number.d.ts +23 -0
- package/lib/src/customtypes/widgets/nestable/Number.js +24 -0
- package/lib/src/customtypes/widgets/nestable/Range.d.ts +23 -0
- package/lib/src/customtypes/widgets/nestable/Range.js +24 -0
- package/lib/src/customtypes/widgets/nestable/RichText.d.ts +73 -0
- package/lib/src/customtypes/widgets/nestable/RichText.js +131 -0
- package/lib/src/customtypes/widgets/nestable/Select.d.ts +21 -0
- package/lib/src/customtypes/widgets/nestable/Select.js +22 -0
- package/lib/src/customtypes/widgets/nestable/Separator.d.ts +14 -0
- package/lib/src/customtypes/widgets/nestable/Separator.js +18 -0
- package/lib/src/customtypes/widgets/nestable/Table.d.ts +21 -0
- package/lib/src/customtypes/widgets/nestable/Table.js +30 -0
- package/lib/src/customtypes/widgets/nestable/Text.d.ts +19 -0
- package/lib/src/customtypes/widgets/nestable/Text.js +21 -0
- package/lib/src/customtypes/widgets/nestable/Timestamp.d.ts +19 -0
- package/lib/src/customtypes/widgets/nestable/Timestamp.js +21 -0
- package/lib/src/customtypes/widgets/nestable/index.d.ts +17 -0
- package/lib/src/customtypes/widgets/nestable/index.js +20 -0
- package/lib/src/customtypes/widgets/shared/ImageConstraint.d.ts +7 -0
- package/lib/src/customtypes/widgets/shared/ImageConstraint.js +31 -0
- package/lib/src/customtypes/widgets/shared/index.d.ts +1 -0
- package/lib/src/customtypes/widgets/shared/index.js +8 -0
- package/lib/src/customtypes/widgets/slices/CompositeSlice.d.ts +455 -0
- package/lib/src/customtypes/widgets/slices/CompositeSlice.js +63 -0
- package/lib/src/customtypes/widgets/slices/LegacySlice.d.ts +442 -0
- package/lib/src/customtypes/widgets/slices/LegacySlice.js +12 -0
- package/lib/src/customtypes/widgets/slices/SharedSlice.d.ts +1807 -0
- package/lib/src/customtypes/widgets/slices/SharedSlice.js +118 -0
- package/lib/src/customtypes/widgets/slices/SharedSliceRef.d.ts +5 -0
- package/lib/src/customtypes/widgets/slices/SharedSliceRef.js +9 -0
- package/lib/src/customtypes/widgets/slices/Slice.d.ts +6 -0
- package/lib/src/customtypes/widgets/slices/Slice.js +2 -0
- package/lib/src/customtypes/widgets/slices/SlicePrimaryWidget.d.ts +1259 -0
- package/lib/src/customtypes/widgets/slices/SlicePrimaryWidget.js +10 -0
- package/lib/src/customtypes/widgets/slices/Slices.d.ts +5917 -0
- package/lib/src/customtypes/widgets/slices/Slices.js +146 -0
- package/lib/src/customtypes/widgets/slices/SlicesTypes.d.ts +6 -0
- package/lib/src/customtypes/widgets/slices/SlicesTypes.js +11 -0
- package/lib/src/customtypes/widgets/slices/index.d.ts +8 -0
- package/lib/src/customtypes/widgets/slices/index.js +11 -0
- package/lib/src/utils/Arrays.d.ts +1 -0
- package/lib/src/utils/Arrays.js +13 -0
- package/lib/src/utils/DocumentId.d.ts +2 -0
- package/lib/src/utils/DocumentId.js +7 -0
- package/lib/src/utils/Objects.d.ts +8 -0
- package/lib/src/utils/Objects.js +42 -0
- package/lib/src/utils/index.d.ts +3 -0
- package/lib/src/utils/index.js +7 -0
- package/lib/src/validators/BasicTypes.d.ts +10 -0
- package/lib/src/validators/BasicTypes.js +25 -0
- package/lib/src/validators/DateFromString.d.ts +3 -0
- package/lib/src/validators/DateFromString.js +11 -0
- package/lib/src/validators/DateFromStringOrNumber.d.ts +3 -0
- package/lib/src/validators/DateFromStringOrNumber.js +10 -0
- package/lib/src/validators/DateFromTsMs.d.ts +3 -0
- package/lib/src/validators/DateFromTsMs.js +10 -0
- package/lib/src/validators/DefaultOrElse.d.ts +5 -0
- package/lib/src/validators/DefaultOrElse.js +21 -0
- package/lib/src/validators/IntFromNumber.d.ts +5 -0
- package/lib/src/validators/IntFromNumber.js +14 -0
- package/lib/src/validators/IntFromPixels.d.ts +8 -0
- package/lib/src/validators/IntFromPixels.js +24 -0
- package/lib/src/validators/NonEmptyString.d.ts +3 -0
- package/lib/src/validators/NonEmptyString.js +6 -0
- package/lib/src/validators/NonEmptyStringOrNull.d.ts +3 -0
- package/lib/src/validators/NonEmptyStringOrNull.js +15 -0
- package/lib/src/validators/NumberOrNull.d.ts +3 -0
- package/lib/src/validators/NumberOrNull.js +6 -0
- package/lib/src/validators/NumberRange.d.ts +32 -0
- package/lib/src/validators/NumberRange.js +40 -0
- package/lib/src/validators/StringFromBoolean.d.ts +5 -0
- package/lib/src/validators/StringFromBoolean.js +10 -0
- package/lib/src/validators/StringFromNumber.d.ts +5 -0
- package/lib/src/validators/StringFromNumber.js +10 -0
- package/lib/src/validators/StringOrNull.d.ts +3 -0
- package/lib/src/validators/StringOrNull.js +6 -0
- package/lib/src/validators/TrimmedString.d.ts +5 -0
- package/lib/src/validators/TrimmedString.js +23 -0
- package/lib/src/validators/function.d.ts +34 -0
- package/lib/src/validators/function.js +100 -0
- package/lib/src/validators/index.d.ts +15 -0
- package/lib/src/validators/index.js +31 -0
- package/package.json +1 -1
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.traverseCustomType = exports.collectSharedSlices = exports.flattenCustomTypeFields = exports.filterMissingSharedSlices = exports.collectWidgets = exports.validateSlices = exports.toStatic = exports.flattenSections = exports.flattenWidgets = exports.CustomType = exports.StaticCustomType = exports.CustomTypeFormat = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const Either_1 = require("fp-ts/lib/Either");
|
|
6
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
7
|
+
const withFallback_1 = require("io-ts-types/lib/withFallback");
|
|
8
|
+
const validators_1 = require("../validators");
|
|
9
|
+
const Section_1 = require("./Section");
|
|
10
|
+
exports.CustomTypeFormat = {
|
|
11
|
+
page: "page",
|
|
12
|
+
custom: "custom",
|
|
13
|
+
};
|
|
14
|
+
class CustomTypeSlicesError extends Error {
|
|
15
|
+
constructor(slices) {
|
|
16
|
+
super();
|
|
17
|
+
Object.defineProperty(this, "slices", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true,
|
|
21
|
+
value: void 0
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(this, "message", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
value: void 0
|
|
28
|
+
});
|
|
29
|
+
this.slices = slices;
|
|
30
|
+
this.message = this._formatError(slices);
|
|
31
|
+
}
|
|
32
|
+
_formatError(slicesRefs) {
|
|
33
|
+
const slicesMsg = slicesRefs.map((ref) => `\t - ${ref}`);
|
|
34
|
+
return `The following slices doesn't exists in your Prismic repository:
|
|
35
|
+
${slicesMsg.join("\n")}
|
|
36
|
+
`;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function customTypeReader(codec) {
|
|
40
|
+
return t.exact(t.intersection([
|
|
41
|
+
t.type({
|
|
42
|
+
id: t.string,
|
|
43
|
+
label: validators_1.StringOrNull,
|
|
44
|
+
repeatable: (0, withFallback_1.withFallback)(t.boolean, true),
|
|
45
|
+
json: t.record(t.string, codec),
|
|
46
|
+
status: (0, withFallback_1.withFallback)(t.boolean, true),
|
|
47
|
+
}),
|
|
48
|
+
t.partial({
|
|
49
|
+
format: (0, withFallback_1.withFallback)(t.keyof(exports.CustomTypeFormat), "custom"),
|
|
50
|
+
}),
|
|
51
|
+
]));
|
|
52
|
+
}
|
|
53
|
+
exports.StaticCustomType = customTypeReader(Section_1.StaticSection);
|
|
54
|
+
exports.CustomType = customTypeReader(Section_1.DynamicSection);
|
|
55
|
+
function flattenWidgets(customType) {
|
|
56
|
+
return Object.entries(customType.json).reduce((acc, [, section]) => {
|
|
57
|
+
const sectionWidgets = Object.entries(section);
|
|
58
|
+
return acc.concat(sectionWidgets);
|
|
59
|
+
}, []);
|
|
60
|
+
}
|
|
61
|
+
exports.flattenWidgets = flattenWidgets;
|
|
62
|
+
function flattenSections(customType) {
|
|
63
|
+
return Object.entries(customType.json).reduce((acc, [, section]) => {
|
|
64
|
+
const sectionWidgets = Object.entries(section);
|
|
65
|
+
return acc.concat(sectionWidgets);
|
|
66
|
+
}, []);
|
|
67
|
+
}
|
|
68
|
+
exports.flattenSections = flattenSections;
|
|
69
|
+
function _retrieveSharedSlicesRef(customType) {
|
|
70
|
+
const slicezones = flattenWidgets(customType).filter(([, widget]) => widget.type === "Slices");
|
|
71
|
+
const allSharedRefs = slicezones.reduce((acc, [, slicezone]) => {
|
|
72
|
+
const sharedRefs = Object.entries(slicezone.config && slicezone.config.choices
|
|
73
|
+
? slicezone.config.choices
|
|
74
|
+
: {})
|
|
75
|
+
.filter(([, slice]) => slice.type === "SharedSlice")
|
|
76
|
+
.map(([key]) => key);
|
|
77
|
+
return acc.concat(sharedRefs);
|
|
78
|
+
}, []);
|
|
79
|
+
return allSharedRefs;
|
|
80
|
+
}
|
|
81
|
+
function _mapSharedSlicesRefs(customType) {
|
|
82
|
+
const refs = _retrieveSharedSlicesRef(customType);
|
|
83
|
+
return function (mapFn) {
|
|
84
|
+
return refs.map(mapFn);
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function toStatic(customType, sharedSlices) {
|
|
88
|
+
const json = Object.entries(customType.json).reduce((acc, [sectionKey, dynSection]) => {
|
|
89
|
+
return {
|
|
90
|
+
...acc,
|
|
91
|
+
[sectionKey]: Section_1.Sections.toStatic(dynSection, sharedSlices),
|
|
92
|
+
};
|
|
93
|
+
}, {});
|
|
94
|
+
return { ...customType, json };
|
|
95
|
+
}
|
|
96
|
+
exports.toStatic = toStatic;
|
|
97
|
+
function validateSlices(customType, sharedSlices) {
|
|
98
|
+
const missingSlices = _mapSharedSlicesRefs(customType)((ref) => {
|
|
99
|
+
const slice = sharedSlices.get(ref);
|
|
100
|
+
const isMissing = !slice;
|
|
101
|
+
if (isMissing)
|
|
102
|
+
return ref;
|
|
103
|
+
return;
|
|
104
|
+
}).filter(Boolean);
|
|
105
|
+
if (missingSlices.length > 0)
|
|
106
|
+
return (0, Either_1.left)(new CustomTypeSlicesError(missingSlices));
|
|
107
|
+
else
|
|
108
|
+
return (0, Either_1.right)(customType);
|
|
109
|
+
}
|
|
110
|
+
exports.validateSlices = validateSlices;
|
|
111
|
+
function collectWidgets(customType, f) {
|
|
112
|
+
const json = Object.entries(customType.json).reduce((acc, [sectionId, section]) => {
|
|
113
|
+
const updatedSection = Object.entries(section).reduce((acc, [ref, widget]) => {
|
|
114
|
+
const updatedWidget = f(ref, widget);
|
|
115
|
+
if (updatedWidget) {
|
|
116
|
+
return { ...acc, [ref]: updatedWidget };
|
|
117
|
+
}
|
|
118
|
+
return acc;
|
|
119
|
+
}, {});
|
|
120
|
+
return { ...acc, [sectionId]: updatedSection };
|
|
121
|
+
}, {});
|
|
122
|
+
return { ...customType, json };
|
|
123
|
+
}
|
|
124
|
+
exports.collectWidgets = collectWidgets;
|
|
125
|
+
function filterMissingSharedSlices(customType, sharedSlices) {
|
|
126
|
+
return collectWidgets(customType, (_widgetId, widget) => {
|
|
127
|
+
if (widget.type === "Slices") {
|
|
128
|
+
if (!widget.config || !widget.config.choices)
|
|
129
|
+
return widget;
|
|
130
|
+
const choices = Object.entries(widget.config.choices).reduce((acc, [sliceId, sliceValue]) => {
|
|
131
|
+
if (sliceValue.type === "SharedSlice" && !sharedSlices.get(sliceId))
|
|
132
|
+
return acc;
|
|
133
|
+
return { ...acc, [sliceId]: sliceValue };
|
|
134
|
+
}, {});
|
|
135
|
+
const config = { ...widget.config, choices };
|
|
136
|
+
return { ...widget, config };
|
|
137
|
+
}
|
|
138
|
+
return widget;
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
exports.filterMissingSharedSlices = filterMissingSharedSlices;
|
|
142
|
+
function flattenCustomTypeFields(customType) {
|
|
143
|
+
return Object.values(customType.json).reduce((acc, tab) => ({
|
|
144
|
+
...acc,
|
|
145
|
+
...tab,
|
|
146
|
+
}), {});
|
|
147
|
+
}
|
|
148
|
+
exports.flattenCustomTypeFields = flattenCustomTypeFields;
|
|
149
|
+
function collectSharedSlices(customType) {
|
|
150
|
+
return Object.entries(customType.fields).reduce((acc, [, w]) => {
|
|
151
|
+
var _a;
|
|
152
|
+
if (w.type === "Slices" || w.type === "Choice") {
|
|
153
|
+
return {
|
|
154
|
+
...acc,
|
|
155
|
+
...Object.entries(((_a = w.config) === null || _a === void 0 ? void 0 : _a.choices) || {}).reduce((sliceZoneAcc, [sliceKey, sliceModel]) => {
|
|
156
|
+
return sliceModel.type === "SharedSlice"
|
|
157
|
+
? { ...sliceZoneAcc, [sliceKey]: sliceModel }
|
|
158
|
+
: sliceZoneAcc;
|
|
159
|
+
}, {}),
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
return acc;
|
|
163
|
+
}, {});
|
|
164
|
+
}
|
|
165
|
+
exports.collectSharedSlices = collectSharedSlices;
|
|
166
|
+
function traverseCustomType(args) {
|
|
167
|
+
const { customType, onField } = args;
|
|
168
|
+
let json;
|
|
169
|
+
for (const [key, section] of Object.entries(customType.json)) {
|
|
170
|
+
const newSection = (0, Section_1.traverseSection)({
|
|
171
|
+
path: [key],
|
|
172
|
+
section,
|
|
173
|
+
onField,
|
|
174
|
+
});
|
|
175
|
+
if (newSection !== section) {
|
|
176
|
+
if (!json)
|
|
177
|
+
json = { ...customType.json };
|
|
178
|
+
json[key] = newSection;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
// returns the traversed model instead of a new one if it didn't change
|
|
182
|
+
return json ? { ...customType, json } : customType;
|
|
183
|
+
}
|
|
184
|
+
exports.traverseCustomType = traverseCustomType;
|