@prismicio/types-internal 2.2.1 → 2.3.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/Document.d.ts +11 -5
- package/lib/content/Document.js +45 -11
- package/lib/content/fields/GroupContent.d.ts +1 -0
- package/lib/content/fields/GroupContent.js +13 -1
- package/lib/content/fields/nestable/BooleanContent.d.ts +2 -0
- package/lib/content/fields/nestable/BooleanContent.js +11 -1
- package/lib/content/fields/nestable/FieldContent/SelectContent.d.ts +2 -0
- package/lib/content/fields/nestable/FieldContent/SelectContent.js +12 -1
- package/lib/content/fields/nestable/NestableContent.d.ts +2 -0
- package/lib/content/fields/nestable/NestableContent.js +12 -1
- package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +1 -0
- package/lib/content/fields/slices/Slice/CompositeSliceContent.js +13 -1
- package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +2 -1
- package/lib/content/fields/slices/Slice/SharedSliceContent.js +16 -1
- package/lib/content/fields/slices/SliceItem.d.ts +3 -0
- package/lib/content/fields/slices/SliceItem.js +24 -1
- package/lib/content/fields/slices/SlicesContent.d.ts +1 -0
- package/lib/content/fields/slices/SlicesContent.js +23 -1
- package/lib/content/fields/withDefaultValues.d.ts +6 -0
- package/lib/content/fields/withDefaultValues.js +38 -0
- package/lib/import/converters/Document.d.ts +4 -0
- package/lib/import/converters/Document.js +21 -0
- package/lib/import/converters/fields/Group.d.ts +4 -0
- package/lib/import/converters/fields/Group.js +14 -0
- package/lib/import/converters/fields/RepeatableZone.d.ts +317 -0
- package/lib/import/converters/fields/RepeatableZone.js +15 -0
- package/lib/import/converters/fields/RepeatableZoneItem.d.ts +11 -0
- package/lib/import/converters/fields/RepeatableZoneItem.js +19 -0
- package/lib/import/converters/fields/Slices/SharedSlice.d.ts +4 -0
- package/lib/import/converters/fields/Slices/SharedSlice.js +19 -0
- package/lib/import/converters/fields/Slices/SharedSliceContent.d.ts +10 -0
- package/lib/import/converters/fields/Slices/SharedSliceContent.js +23 -0
- package/lib/import/converters/fields/Slices/Slices.d.ts +4 -0
- package/lib/import/converters/fields/Slices/Slices.js +16 -0
- package/lib/import/converters/fields/Slices/index.d.ts +1 -0
- package/lib/import/converters/fields/Slices/index.js +4 -0
- package/lib/import/converters/fields/UID.d.ts +3 -0
- package/lib/import/converters/fields/UID.js +10 -0
- package/lib/import/converters/fields/index.d.ts +4 -0
- package/lib/import/converters/fields/index.js +7 -0
- package/lib/import/converters/fields/nestable/Boolean.d.ts +3 -0
- package/lib/import/converters/fields/nestable/Boolean.js +12 -0
- package/lib/import/converters/fields/nestable/Color.d.ts +3 -0
- package/lib/import/converters/fields/nestable/Color.js +13 -0
- package/lib/import/converters/fields/nestable/Date.d.ts +3 -0
- package/lib/import/converters/fields/nestable/Date.js +15 -0
- package/lib/import/converters/fields/nestable/Embed.d.ts +4 -0
- package/lib/import/converters/fields/nestable/Embed.js +32 -0
- package/lib/import/converters/fields/nestable/GeoPoint.d.ts +3 -0
- package/lib/import/converters/fields/nestable/GeoPoint.js +15 -0
- package/lib/import/converters/fields/nestable/Image.d.ts +28 -0
- package/lib/import/converters/fields/nestable/Image.js +67 -0
- package/lib/import/converters/fields/nestable/Link.d.ts +4 -0
- package/lib/import/converters/fields/nestable/Link.js +70 -0
- package/lib/import/converters/fields/nestable/Nestable.d.ts +5 -0
- package/lib/import/converters/fields/nestable/Nestable.js +35 -0
- package/lib/import/converters/fields/nestable/Number.d.ts +3 -0
- package/lib/import/converters/fields/nestable/Number.js +13 -0
- package/lib/import/converters/fields/nestable/RichText/embedBlock.d.ts +4 -0
- package/lib/import/converters/fields/nestable/RichText/embedBlock.js +14 -0
- package/lib/import/converters/fields/nestable/RichText/imageBlock.d.ts +4 -0
- package/lib/import/converters/fields/nestable/RichText/imageBlock.js +12 -0
- package/lib/import/converters/fields/nestable/RichText/index.d.ts +4 -0
- package/lib/import/converters/fields/nestable/RichText/index.js +22 -0
- package/lib/import/converters/fields/nestable/RichText/textBlock.d.ts +4 -0
- package/lib/import/converters/fields/nestable/RichText/textBlock.js +54 -0
- package/lib/import/converters/fields/nestable/Select.d.ts +3 -0
- package/lib/import/converters/fields/nestable/Select.js +13 -0
- package/lib/import/converters/fields/nestable/Text.d.ts +3 -0
- package/lib/import/converters/fields/nestable/Text.js +13 -0
- package/lib/import/converters/fields/nestable/Timestamp.d.ts +3 -0
- package/lib/import/converters/fields/nestable/Timestamp.js +13 -0
- package/lib/import/converters/fields/nestable/index.d.ts +13 -0
- package/lib/import/converters/fields/nestable/index.js +16 -0
- package/lib/import/converters/index.d.ts +2 -0
- package/lib/import/converters/index.js +5 -0
- package/lib/import/index.d.ts +2 -0
- package/lib/import/index.js +5 -0
- package/lib/import/validators/Document.d.ts +6 -0
- package/lib/import/validators/Document.js +64 -0
- package/lib/import/validators/fields/ImportContent.d.ts +5 -0
- package/lib/import/validators/fields/ImportContent.js +21 -0
- package/lib/import/validators/fields/ImportField.d.ts +141 -0
- package/lib/import/validators/fields/ImportField.js +33 -0
- package/lib/import/validators/fields/ImportGroup.d.ts +345 -0
- package/lib/import/validators/fields/ImportGroup.js +27 -0
- package/lib/import/validators/fields/ImportSlices/ImportSlices.d.ts +8 -0
- package/lib/import/validators/fields/ImportSlices/ImportSlices.js +30 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.d.ts +16 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.js +61 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/errors.d.ts +4 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/errors.js +7 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.d.ts +2 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.js +15 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.d.ts +9 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.js +39 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.d.ts +11 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.js +24 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.d.ts +11 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.js +24 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/index.d.ts +4 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/index.js +7 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/index.d.ts +3 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/index.js +6 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/utils.d.ts +342 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/utils.js +11 -0
- package/lib/import/validators/fields/ImportSlices/index.d.ts +1 -0
- package/lib/import/validators/fields/ImportSlices/index.js +4 -0
- package/lib/import/validators/fields/ImportSlices/utils.d.ts +4 -0
- package/lib/import/validators/fields/ImportSlices/utils.js +35 -0
- package/lib/import/validators/fields/RepeatableZone.d.ts +11 -0
- package/lib/import/validators/fields/RepeatableZone.js +14 -0
- package/lib/import/validators/fields/RepeatableZoneItem.d.ts +11 -0
- package/lib/import/validators/fields/RepeatableZoneItem.js +39 -0
- package/lib/import/validators/fields/UID.d.ts +6 -0
- package/lib/import/validators/fields/UID.js +15 -0
- package/lib/import/validators/fields/index.d.ts +4 -0
- package/lib/import/validators/fields/index.js +7 -0
- package/lib/import/validators/fields/nestable/Boolean.d.ts +6 -0
- package/lib/import/validators/fields/nestable/Boolean.js +6 -0
- package/lib/import/validators/fields/nestable/Color.d.ts +6 -0
- package/lib/import/validators/fields/nestable/Color.js +15 -0
- package/lib/import/validators/fields/nestable/Date.d.ts +6 -0
- package/lib/import/validators/fields/nestable/Date.js +19 -0
- package/lib/import/validators/fields/nestable/Embed.d.ts +13 -0
- package/lib/import/validators/fields/nestable/Embed.js +31 -0
- package/lib/import/validators/fields/nestable/GeoPoint.d.ts +13 -0
- package/lib/import/validators/fields/nestable/GeoPoint.js +13 -0
- package/lib/import/validators/fields/nestable/Image/default.d.ts +22 -0
- package/lib/import/validators/fields/nestable/Image/default.js +19 -0
- package/lib/import/validators/fields/nestable/Image/index.d.ts +26 -0
- package/lib/import/validators/fields/nestable/Image/index.js +32 -0
- package/lib/import/validators/fields/nestable/Image/merge.d.ts +23 -0
- package/lib/import/validators/fields/nestable/Image/merge.js +44 -0
- package/lib/import/validators/fields/nestable/Image/model.d.ts +18 -0
- package/lib/import/validators/fields/nestable/Image/model.js +2 -0
- package/lib/import/validators/fields/nestable/Image/validators.d.ts +132 -0
- package/lib/import/validators/fields/nestable/Image/validators.js +43 -0
- package/lib/import/validators/fields/nestable/ImportRichText/ImportBlock.d.ts +6 -0
- package/lib/import/validators/fields/nestable/ImportRichText/ImportBlock.js +25 -0
- package/lib/import/validators/fields/nestable/ImportRichText/ImportRichText.d.ts +24 -0
- package/lib/import/validators/fields/nestable/ImportRichText/ImportRichText.js +32 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportBlockType.d.ts +6 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportBlockType.js +18 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportEmbedBlock.d.ts +10 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportEmbedBlock.js +11 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.d.ts +22 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.js +13 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportTextBlock.d.ts +78 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportTextBlock.js +43 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/Span.d.ts +79 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/Span.js +27 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/index.d.ts +4 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/index.js +7 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/HyperlinkSpan.d.ts +24 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/HyperlinkSpan.js +18 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/LabelSpan.d.ts +12 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/LabelSpan.js +16 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/SpanLocation.d.ts +5 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/SpanLocation.js +10 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.d.ts +15 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.js +20 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/index.d.ts +2 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/index.js +5 -0
- package/lib/import/validators/fields/nestable/ImportRichText/index.d.ts +2 -0
- package/lib/import/validators/fields/nestable/ImportRichText/index.js +7 -0
- package/lib/import/validators/fields/nestable/Link.d.ts +53 -0
- package/lib/import/validators/fields/nestable/Link.js +35 -0
- package/lib/import/validators/fields/nestable/Nestable.d.ts +192 -0
- package/lib/import/validators/fields/nestable/Nestable.js +71 -0
- package/lib/import/validators/fields/nestable/Number.d.ts +17 -0
- package/lib/import/validators/fields/nestable/Number.js +17 -0
- package/lib/import/validators/fields/nestable/Select.d.ts +16 -0
- package/lib/import/validators/fields/nestable/Select.js +19 -0
- package/lib/import/validators/fields/nestable/Text.d.ts +6 -0
- package/lib/import/validators/fields/nestable/Text.js +6 -0
- package/lib/import/validators/fields/nestable/Timestamp.d.ts +7 -0
- package/lib/import/validators/fields/nestable/Timestamp.js +19 -0
- package/lib/import/validators/fields/nestable/index.d.ts +14 -0
- package/lib/import/validators/fields/nestable/index.js +19 -0
- package/lib/import/validators/index.d.ts +2 -0
- package/lib/import/validators/index.js +5 -0
- package/package.json +1 -1
- package/src/content/Document.ts +74 -18
- package/src/content/fields/GroupContent.ts +16 -0
- package/src/content/fields/nestable/BooleanContent.ts +11 -0
- package/src/content/fields/nestable/FieldContent/SelectContent.ts +12 -1
- package/src/content/fields/nestable/NestableContent.ts +16 -0
- package/src/content/fields/slices/Slice/CompositeSliceContent.ts +25 -0
- package/src/content/fields/slices/Slice/SharedSliceContent.ts +32 -1
- package/src/content/fields/slices/SliceItem.ts +43 -1
- package/src/content/fields/slices/SlicesContent.ts +30 -0
- package/src/content/fields/withDefaultValues.ts +48 -0
|
@@ -3190,7 +3190,7 @@ declare function extractMetadata(data: {
|
|
|
3190
3190
|
slugs: ReadonlyArray<string>;
|
|
3191
3191
|
uid: string | undefined;
|
|
3192
3192
|
};
|
|
3193
|
-
declare function parseLegacyDocument(legacyDoc: unknown, customType: {
|
|
3193
|
+
declare function parseLegacyDocument(legacyDoc: unknown, customType: StaticCustomType | {
|
|
3194
3194
|
customTypeId: string;
|
|
3195
3195
|
fields: Record<string, StaticWidget>;
|
|
3196
3196
|
}): Document | undefined;
|
|
@@ -5743,12 +5743,18 @@ export declare const DocumentLegacy: {
|
|
|
5743
5743
|
parse: typeof parseLegacyDocument;
|
|
5744
5744
|
encode: typeof encodeToLegacyDocument;
|
|
5745
5745
|
};
|
|
5746
|
+
export declare function fillDocumentWithDefaultValues(customType: StaticCustomType | {
|
|
5747
|
+
customTypeId: string;
|
|
5748
|
+
fields: Record<string, StaticWidget>;
|
|
5749
|
+
}, document: Document): Document;
|
|
5746
5750
|
/**
|
|
5747
|
-
*
|
|
5748
|
-
*
|
|
5751
|
+
* @param model: Can be optional if we simply want to loop through the content
|
|
5752
|
+
* without any consideration for the attached model
|
|
5749
5753
|
* @param document: The content we actually want to iterate on in an immutable fashion
|
|
5750
|
-
* @param transform: A user function that provides a way to transform any kind
|
|
5751
|
-
*
|
|
5754
|
+
* @param transform: A user function that provides a way to transform any kind
|
|
5755
|
+
* of content wherever it is in a structured Prismic object content.
|
|
5756
|
+
* @returns A transformed document with the user's transformation applied with
|
|
5757
|
+
* the transform function
|
|
5752
5758
|
*/
|
|
5753
5759
|
export declare function traverseDocument({ document, customType, }: {
|
|
5754
5760
|
document: Document;
|
package/lib/content/Document.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.migrateDocument = exports.collectWidgets = exports.traverseDocument = exports.DocumentLegacy = exports.Document = void 0;
|
|
3
|
+
exports.migrateDocument = exports.collectWidgets = exports.traverseDocument = exports.fillDocumentWithDefaultValues = exports.DocumentLegacy = exports.Document = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fp_ts_1 = require("fp-ts");
|
|
6
6
|
const Either_1 = require("fp-ts/lib/Either");
|
|
@@ -93,12 +93,52 @@ exports.DocumentLegacy = {
|
|
|
93
93
|
parse: parseLegacyDocument,
|
|
94
94
|
encode: encodeToLegacyDocument,
|
|
95
95
|
};
|
|
96
|
+
function simplifyCustomType(customType) {
|
|
97
|
+
return {
|
|
98
|
+
customTypeId: customType === null || customType === void 0 ? void 0 : customType.id,
|
|
99
|
+
fields: Object.fromEntries((0, customtypes_1.flattenSections)(customType)),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function fillDocumentWithDefaultValues(customType, document) {
|
|
103
|
+
const { fields } = customType && customtypes_1.StaticCustomType.is(customType)
|
|
104
|
+
? simplifyCustomType(customType)
|
|
105
|
+
: customType;
|
|
106
|
+
return Object.entries(fields).reduce((updatedDocument, [fieldKey, fieldDef]) => {
|
|
107
|
+
const fieldContent = document[fieldKey];
|
|
108
|
+
const updatedField = (() => {
|
|
109
|
+
switch (fieldDef.type) {
|
|
110
|
+
case "Group":
|
|
111
|
+
return (0, fields_1.isGroupContent)(fieldContent)
|
|
112
|
+
? (0, fields_1.groupContentWithDefaultValues)(fieldDef, fieldContent)
|
|
113
|
+
: fieldContent;
|
|
114
|
+
case "Choice":
|
|
115
|
+
case "Slices":
|
|
116
|
+
return (0, fields_1.isSlicesContent)(fieldContent)
|
|
117
|
+
? (0, fields_1.slicesContentWithDefaultValues)(fieldDef, fieldContent)
|
|
118
|
+
: fieldContent;
|
|
119
|
+
default:
|
|
120
|
+
return fieldContent === undefined && customtypes_1.NestableWidget.is(fieldDef)
|
|
121
|
+
? (0, fields_1.NestableContentDefaultValue)(fieldDef)
|
|
122
|
+
: fieldContent;
|
|
123
|
+
}
|
|
124
|
+
})();
|
|
125
|
+
return updatedField
|
|
126
|
+
? {
|
|
127
|
+
...updatedDocument,
|
|
128
|
+
[fieldKey]: updatedField,
|
|
129
|
+
}
|
|
130
|
+
: updatedDocument;
|
|
131
|
+
}, document);
|
|
132
|
+
}
|
|
133
|
+
exports.fillDocumentWithDefaultValues = fillDocumentWithDefaultValues;
|
|
96
134
|
/**
|
|
97
|
-
*
|
|
98
|
-
*
|
|
135
|
+
* @param model: Can be optional if we simply want to loop through the content
|
|
136
|
+
* without any consideration for the attached model
|
|
99
137
|
* @param document: The content we actually want to iterate on in an immutable fashion
|
|
100
|
-
* @param transform: A user function that provides a way to transform any kind
|
|
101
|
-
*
|
|
138
|
+
* @param transform: A user function that provides a way to transform any kind
|
|
139
|
+
* of content wherever it is in a structured Prismic object content.
|
|
140
|
+
* @returns A transformed document with the user's transformation applied with
|
|
141
|
+
* the transform function
|
|
102
142
|
*/
|
|
103
143
|
function traverseDocument({ document, customType, }) {
|
|
104
144
|
const model = customType && customtypes_1.StaticCustomType.is(customType)
|
|
@@ -154,12 +194,6 @@ function traverseDocument({ document, customType, }) {
|
|
|
154
194
|
};
|
|
155
195
|
}
|
|
156
196
|
exports.traverseDocument = traverseDocument;
|
|
157
|
-
function simplifyCustomType(customType) {
|
|
158
|
-
return {
|
|
159
|
-
customTypeId: customType === null || customType === void 0 ? void 0 : customType.id,
|
|
160
|
-
fields: Object.fromEntries((0, customtypes_1.flattenSections)(customType)),
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
197
|
// /**
|
|
164
198
|
// * The goal is to be able to collect all widgets or slices of a given type at any level of nesting inside a prismic content
|
|
165
199
|
// *
|
|
@@ -1760,6 +1760,7 @@ export declare const GroupContent: t.ExactC<t.TypeC<{
|
|
|
1760
1760
|
}>>>;
|
|
1761
1761
|
}>>;
|
|
1762
1762
|
export declare type GroupContent = t.TypeOf<typeof GroupContent>;
|
|
1763
|
+
export declare function groupContentWithDefaultValues(customType: Group, content: GroupContent): GroupContent;
|
|
1763
1764
|
export declare function traverseGroupContent({ path, key, apiId, model, content, }: {
|
|
1764
1765
|
path: ContentPath;
|
|
1765
1766
|
key: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.traverseGroupItemsContent = exports.traverseGroupContent = exports.GroupContent = exports.isGroupContent = exports.GroupContentType = exports.GroupLegacy = exports.GroupItemLegacy = exports.GroupItemContent = exports.GroupItemContentType = void 0;
|
|
3
|
+
exports.traverseGroupItemsContent = exports.traverseGroupContent = exports.groupContentWithDefaultValues = exports.GroupContent = exports.isGroupContent = exports.GroupContentType = exports.GroupLegacy = exports.GroupItemLegacy = exports.GroupItemContent = exports.GroupItemContentType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fp_ts_1 = require("fp-ts");
|
|
6
6
|
const Either_1 = require("fp-ts/lib/Either");
|
|
@@ -9,6 +9,7 @@ const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
|
9
9
|
const LegacyContentCtx_1 = require("../LegacyContentCtx");
|
|
10
10
|
const utils_1 = require("../utils");
|
|
11
11
|
const nestable_1 = require("./nestable");
|
|
12
|
+
const withDefaultValues_1 = require("./withDefaultValues");
|
|
12
13
|
exports.GroupItemContentType = "GroupItemContent";
|
|
13
14
|
exports.GroupItemContent = t.strict({
|
|
14
15
|
__TYPE__: t.literal(exports.GroupItemContentType),
|
|
@@ -81,6 +82,17 @@ exports.GroupContent = t.strict({
|
|
|
81
82
|
__TYPE__: t.literal(exports.GroupContentType),
|
|
82
83
|
value: t.array(exports.GroupItemContent),
|
|
83
84
|
});
|
|
85
|
+
function groupContentWithDefaultValues(customType, content) {
|
|
86
|
+
var _a;
|
|
87
|
+
const fields = (_a = customType.config) === null || _a === void 0 ? void 0 : _a.fields;
|
|
88
|
+
if (!fields)
|
|
89
|
+
return content;
|
|
90
|
+
return {
|
|
91
|
+
...content,
|
|
92
|
+
value: (0, withDefaultValues_1.repeatableContentWithDefaultNestableContentValues)(fields, content.value),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
exports.groupContentWithDefaultValues = groupContentWithDefaultValues;
|
|
84
96
|
function traverseGroupContent({ path, key, apiId, model, content, }) {
|
|
85
97
|
return (transform) => {
|
|
86
98
|
var _a;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
|
+
import type { BooleanField } from "../../../customtypes";
|
|
2
3
|
import type { LegacyContentCtx, WithTypes } from "../../LegacyContentCtx";
|
|
3
4
|
export declare const BooleanContentType = "BooleanContent";
|
|
4
5
|
export declare const isBooleanContent: (u: unknown) => u is {
|
|
@@ -14,3 +15,4 @@ export declare const BooleanContent: t.ExactC<t.TypeC<{
|
|
|
14
15
|
value: t.BooleanC;
|
|
15
16
|
}>>;
|
|
16
17
|
export declare type BooleanContent = t.TypeOf<typeof BooleanContent>;
|
|
18
|
+
export declare const BooleanContentDefaultValue: (field: BooleanField) => BooleanContent | undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BooleanContent = exports.BooleanLegacy = exports.isBooleanContent = exports.BooleanContentType = void 0;
|
|
3
|
+
exports.BooleanContentDefaultValue = exports.BooleanContent = exports.BooleanLegacy = exports.isBooleanContent = exports.BooleanContentType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fp_ts_1 = require("fp-ts");
|
|
6
6
|
const function_1 = require("fp-ts/lib/function");
|
|
@@ -22,3 +22,13 @@ exports.BooleanContent = t.strict({
|
|
|
22
22
|
__TYPE__: t.literal(exports.BooleanContentType),
|
|
23
23
|
value: t.boolean,
|
|
24
24
|
});
|
|
25
|
+
const BooleanContentDefaultValue = (field) => {
|
|
26
|
+
var _a;
|
|
27
|
+
return ((_a = field.config) === null || _a === void 0 ? void 0 : _a.default_value) !== undefined
|
|
28
|
+
? {
|
|
29
|
+
__TYPE__: exports.BooleanContentType,
|
|
30
|
+
value: field.config.default_value || false,
|
|
31
|
+
}
|
|
32
|
+
: undefined;
|
|
33
|
+
};
|
|
34
|
+
exports.BooleanContentDefaultValue = BooleanContentDefaultValue;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
|
+
import { Select } from "../../../../customtypes/widgets";
|
|
2
3
|
import type { LegacyContentCtx, WithTypes } from "../../../LegacyContentCtx";
|
|
3
4
|
export declare const isSelectContent: (u: unknown) => u is {
|
|
4
5
|
type: "Select";
|
|
@@ -16,3 +17,4 @@ export declare const SelectContent: t.ExactC<t.TypeC<{
|
|
|
16
17
|
__TYPE__: t.LiteralC<"FieldContent">;
|
|
17
18
|
}>>;
|
|
18
19
|
export declare type SelectContent = t.TypeOf<typeof SelectContent>;
|
|
20
|
+
export declare const SelectContentDefaultValue: (field: Select) => SelectContent | undefined;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SelectContent = exports.SelectLegacy = exports.isSelectContent = void 0;
|
|
3
|
+
exports.SelectContentDefaultValue = exports.SelectContent = exports.SelectLegacy = exports.isSelectContent = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fp_ts_1 = require("fp-ts");
|
|
6
6
|
const function_1 = require("fp-ts/lib/function");
|
|
@@ -32,3 +32,14 @@ exports.SelectContent = t.strict({
|
|
|
32
32
|
value: TrimmedString_1.default,
|
|
33
33
|
__TYPE__: t.literal(common_1.FieldContentType),
|
|
34
34
|
});
|
|
35
|
+
const SelectContentDefaultValue = (field) => {
|
|
36
|
+
var _a;
|
|
37
|
+
return ((_a = field.config) === null || _a === void 0 ? void 0 : _a.default_value)
|
|
38
|
+
? {
|
|
39
|
+
__TYPE__: common_1.FieldContentType,
|
|
40
|
+
type: widgets_1.SelectFieldType,
|
|
41
|
+
value: field.config.default_value || "",
|
|
42
|
+
}
|
|
43
|
+
: undefined;
|
|
44
|
+
};
|
|
45
|
+
exports.SelectContentDefaultValue = SelectContentDefaultValue;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
|
+
import type { NestableWidget } from "../../../customtypes";
|
|
2
3
|
import type { LegacyContentCtx } from "../../LegacyContentCtx";
|
|
3
4
|
export declare const NestableContent: t.UnionC<[t.ExactC<t.TypeC<{
|
|
4
5
|
type: t.StringC;
|
|
@@ -395,6 +396,7 @@ export declare const NestableContent: t.UnionC<[t.ExactC<t.TypeC<{
|
|
|
395
396
|
}>>]>;
|
|
396
397
|
export declare type NestableContent = t.TypeOf<typeof NestableContent>;
|
|
397
398
|
export declare type NestableContentType = NestableContent["__TYPE__"];
|
|
399
|
+
export declare const NestableContentDefaultValue: (widgetDef: NestableWidget) => NestableContent | undefined;
|
|
398
400
|
export declare const isNestableContent: (u: unknown) => u is {
|
|
399
401
|
type: string;
|
|
400
402
|
__TYPE__: "EmptyContent";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NestableLegacy = exports.isNestableContent = exports.NestableContent = void 0;
|
|
3
|
+
exports.NestableLegacy = exports.isNestableContent = exports.NestableContentDefaultValue = exports.NestableContent = 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"));
|
|
@@ -33,6 +33,17 @@ exports.NestableContent = t.union([
|
|
|
33
33
|
RichTextContent_1.RichTextContent,
|
|
34
34
|
SeparatorContent_1.SeparatorContent,
|
|
35
35
|
]);
|
|
36
|
+
const NestableContentDefaultValue = (widgetDef) => {
|
|
37
|
+
switch (widgetDef.type) {
|
|
38
|
+
case "Boolean":
|
|
39
|
+
return (0, BooleanContent_1.BooleanContentDefaultValue)(widgetDef);
|
|
40
|
+
case "Select":
|
|
41
|
+
return (0, FieldContent_1.SelectContentDefaultValue)(widgetDef);
|
|
42
|
+
default:
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
exports.NestableContentDefaultValue = NestableContentDefaultValue;
|
|
36
47
|
const isNestableContent = (u) => (0, FieldContent_1.isTextContent)(u) ||
|
|
37
48
|
(0, FieldContent_1.isColorContent)(u) ||
|
|
38
49
|
(0, FieldContent_1.isDateContent)(u) ||
|
|
@@ -2070,6 +2070,7 @@ export declare const CompositeSliceContent: t.ExactC<t.TypeC<{
|
|
|
2070
2070
|
}>>>;
|
|
2071
2071
|
}>>;
|
|
2072
2072
|
export declare type CompositeSliceContent = t.TypeOf<typeof CompositeSliceContent>;
|
|
2073
|
+
export declare function compositeSliceContentWithDefaultValues(customType: CompositeSlice, content: CompositeSliceContent): CompositeSliceContent;
|
|
2073
2074
|
export declare function traverseCompositeSliceContent({ path, sliceKey, sliceName, model, content, }: {
|
|
2074
2075
|
path: ContentPath;
|
|
2075
2076
|
sliceKey: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.migrateCompositeSlice = exports.traverseCompositeSliceContent = exports.CompositeSliceContent = exports.CompositeSliceLegacy = exports.isCompositeSliceContent = exports.CompositeSliceContentType = void 0;
|
|
3
|
+
exports.migrateCompositeSlice = exports.traverseCompositeSliceContent = exports.compositeSliceContentWithDefaultValues = exports.CompositeSliceContent = exports.CompositeSliceLegacy = exports.isCompositeSliceContent = exports.CompositeSliceContentType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fp_ts_1 = require("fp-ts");
|
|
6
6
|
const Either_1 = require("fp-ts/lib/Either");
|
|
@@ -10,6 +10,7 @@ const LegacyContentCtx_1 = require("../../../LegacyContentCtx");
|
|
|
10
10
|
const utils_1 = require("../../../utils");
|
|
11
11
|
const GroupContent_1 = require("../../GroupContent");
|
|
12
12
|
const nestable_1 = require("../../nestable");
|
|
13
|
+
const withDefaultValues_1 = require("../../withDefaultValues");
|
|
13
14
|
const RepeatableContent_1 = require("./RepeatableContent");
|
|
14
15
|
exports.CompositeSliceContentType = "CompositeSliceContent";
|
|
15
16
|
const isCompositeSliceContent = (u) => (0, utils_1.hasContentType)(u) && u.__TYPE__ === exports.CompositeSliceContentType;
|
|
@@ -80,6 +81,17 @@ exports.CompositeSliceContent = t.strict({
|
|
|
80
81
|
nonRepeat: t.record(t.string, nestable_1.NestableContent),
|
|
81
82
|
repeat: RepeatableContent_1.RepeatableWidgets,
|
|
82
83
|
});
|
|
84
|
+
function compositeSliceContentWithDefaultValues(customType, content) {
|
|
85
|
+
var _a, _b;
|
|
86
|
+
const updatedNonRepeatContent = (0, withDefaultValues_1.withDefaultNestableContentValues)((_a = customType["non-repeat"]) !== null && _a !== void 0 ? _a : {}, content.nonRepeat);
|
|
87
|
+
const updatedRepeatContent = (0, withDefaultValues_1.repeatableContentWithDefaultNestableContentValues)((_b = customType.repeat) !== null && _b !== void 0 ? _b : {}, content.repeat);
|
|
88
|
+
return {
|
|
89
|
+
...content,
|
|
90
|
+
nonRepeat: updatedNonRepeatContent,
|
|
91
|
+
repeat: updatedRepeatContent,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
exports.compositeSliceContentWithDefaultValues = compositeSliceContentWithDefaultValues;
|
|
83
95
|
function traverseCompositeSliceContent({ path, sliceKey, sliceName, model, content, }) {
|
|
84
96
|
return (transformWidget, transformSlice) => {
|
|
85
97
|
const primary = Object.entries(content.widget.nonRepeat).reduce((acc, [fieldKey, fieldContent]) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
2
|
import type { ContentPath, TraverseSliceContentFn, TraverseWidgetContentFn } from "../../../../_internal/utils";
|
|
3
|
-
import type { VariationFields } from "../../../../customtypes";
|
|
3
|
+
import type { SharedSlice, VariationFields } from "../../../../customtypes";
|
|
4
4
|
import { LegacyContentCtx, WithTypes } from "../../../LegacyContentCtx";
|
|
5
5
|
import type { SharedSliceItemContent } from "../SliceItem";
|
|
6
6
|
export declare const SharedSliceContentType = "SharedSliceContent";
|
|
@@ -2074,6 +2074,7 @@ export declare const SharedSliceContent: t.ExactC<t.TypeC<{
|
|
|
2074
2074
|
}>>>;
|
|
2075
2075
|
}>>;
|
|
2076
2076
|
export declare type SharedSliceContent = t.TypeOf<typeof SharedSliceContent>;
|
|
2077
|
+
export declare function sharedSliceContentWithDefaultValues(customType: SharedSlice, content: SharedSliceContent): SharedSliceContent;
|
|
2077
2078
|
export declare function traverseSharedSliceContent({ path, sliceKey, sliceName, model, content, }: {
|
|
2078
2079
|
path: ContentPath;
|
|
2079
2080
|
sliceKey: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.traverseSharedSliceContent = exports.SharedSliceContent = exports.SharedSliceLegacy = exports.isSharedSliceContent = exports.SharedSliceContentType = void 0;
|
|
3
|
+
exports.traverseSharedSliceContent = exports.sharedSliceContentWithDefaultValues = exports.SharedSliceContent = exports.SharedSliceLegacy = exports.isSharedSliceContent = exports.SharedSliceContentType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fp_ts_1 = require("fp-ts");
|
|
6
6
|
const Either_1 = require("fp-ts/lib/Either");
|
|
@@ -11,6 +11,7 @@ const LegacyContentCtx_1 = require("../../../LegacyContentCtx");
|
|
|
11
11
|
const utils_1 = require("../../../utils");
|
|
12
12
|
const GroupContent_1 = require("../../GroupContent");
|
|
13
13
|
const nestable_1 = require("../../nestable");
|
|
14
|
+
const withDefaultValues_1 = require("../../withDefaultValues");
|
|
14
15
|
const RepeatableContent_1 = require("./RepeatableContent");
|
|
15
16
|
exports.SharedSliceContentType = "SharedSliceContent";
|
|
16
17
|
const isSharedSliceContent = (u) => (0, utils_1.hasContentType)(u) && u.__TYPE__ === exports.SharedSliceContentType;
|
|
@@ -97,6 +98,20 @@ exports.SharedSliceContent = t.strict({
|
|
|
97
98
|
primary: t.record(t.string, nestable_1.NestableContent),
|
|
98
99
|
items: RepeatableContent_1.RepeatableWidgets,
|
|
99
100
|
});
|
|
101
|
+
function sharedSliceContentWithDefaultValues(customType, content) {
|
|
102
|
+
var _a, _b;
|
|
103
|
+
const variationConfig = customType.variations.find((v) => v.id === content.variation);
|
|
104
|
+
const primaryConfig = (_a = variationConfig === null || variationConfig === void 0 ? void 0 : variationConfig.primary) !== null && _a !== void 0 ? _a : {};
|
|
105
|
+
const itemsConfig = (_b = variationConfig === null || variationConfig === void 0 ? void 0 : variationConfig.items) !== null && _b !== void 0 ? _b : {};
|
|
106
|
+
const updatedPrimaryContent = (0, withDefaultValues_1.withDefaultNestableContentValues)(primaryConfig, content.primary);
|
|
107
|
+
const updatedItemsContent = (0, withDefaultValues_1.repeatableContentWithDefaultNestableContentValues)(itemsConfig, content.items);
|
|
108
|
+
return {
|
|
109
|
+
...content,
|
|
110
|
+
primary: updatedPrimaryContent,
|
|
111
|
+
items: updatedItemsContent,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
exports.sharedSliceContentWithDefaultValues = sharedSliceContentWithDefaultValues;
|
|
100
115
|
function traverseSharedSliceContent({ path, sliceKey, sliceName, model, content, }) {
|
|
101
116
|
return (transformWidget, transformSlice) => {
|
|
102
117
|
const primary = Object.entries(content.widget.primary).reduce((acc, [fieldKey, fieldContent]) => {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
2
|
import type { TraverseSliceContentFn } from "../../../_internal/utils";
|
|
3
|
+
import type { StaticSlice } from "../../../customtypes";
|
|
3
4
|
import { LegacyContentCtx, WithTypes } from "../../LegacyContentCtx";
|
|
5
|
+
import { SliceContent } from "./Slice";
|
|
4
6
|
import { CompositeSliceContent } from "./Slice/CompositeSliceContent";
|
|
5
7
|
import { SharedSliceContent } from "./Slice/SharedSliceContent";
|
|
6
8
|
import { SimpleSliceContent } from "./Slice/SimpleSliceContent";
|
|
@@ -2396,6 +2398,7 @@ export declare type SimpleSliceItemContent = Omit<SliceItemContent, "widget"> &
|
|
|
2396
2398
|
widget: SimpleSliceContent;
|
|
2397
2399
|
};
|
|
2398
2400
|
export declare function isSimpleSliceItemContent(item: SliceItemContent): item is SimpleSliceItemContent;
|
|
2401
|
+
export declare function sliceItemContentWithDefaultValues(customType: StaticSlice, content: SliceContent): SliceContent;
|
|
2399
2402
|
export declare const SlicesItemLegacy: (ctx: LegacyContentCtx) => t.Type<{
|
|
2400
2403
|
key: string;
|
|
2401
2404
|
name: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.migrateSliceItem = exports.SlicesItemLegacy = exports.isSimpleSliceItemContent = exports.isCompositeSliceItemContent = exports.isSharedSliceItemContent = exports.SliceItemContent = void 0;
|
|
3
|
+
exports.migrateSliceItem = exports.SlicesItemLegacy = exports.sliceItemContentWithDefaultValues = exports.isSimpleSliceItemContent = exports.isCompositeSliceItemContent = exports.isSharedSliceItemContent = exports.SliceItemContent = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fp_ts_1 = require("fp-ts");
|
|
6
6
|
const Either_1 = require("fp-ts/lib/Either");
|
|
@@ -10,6 +10,7 @@ const function_2 = require("../../../validators/function");
|
|
|
10
10
|
const LegacyContentCtx_1 = require("../../LegacyContentCtx");
|
|
11
11
|
const GroupContent_1 = require("../GroupContent");
|
|
12
12
|
const nestable_1 = require("../nestable");
|
|
13
|
+
const withDefaultValues_1 = require("../withDefaultValues");
|
|
13
14
|
const Slice_1 = require("./Slice");
|
|
14
15
|
const CompositeSliceContent_1 = require("./Slice/CompositeSliceContent");
|
|
15
16
|
const SharedSliceContent_1 = require("./Slice/SharedSliceContent");
|
|
@@ -32,6 +33,28 @@ function isSimpleSliceItemContent(item) {
|
|
|
32
33
|
return (0, GroupContent_1.isGroupContent)(item.widget) || (0, nestable_1.isNestableContent)(item.widget);
|
|
33
34
|
}
|
|
34
35
|
exports.isSimpleSliceItemContent = isSimpleSliceItemContent;
|
|
36
|
+
function sliceItemContentWithDefaultValues(customType, content) {
|
|
37
|
+
var _a;
|
|
38
|
+
if (customType.type === "SharedSlice" && (0, SharedSliceContent_1.isSharedSliceContent)(content)) {
|
|
39
|
+
return (0, Slice_1.sharedSliceContentWithDefaultValues)(customType, content);
|
|
40
|
+
}
|
|
41
|
+
if (customType.type === "Slice" && (0, CompositeSliceContent_1.isCompositeSliceContent)(content)) {
|
|
42
|
+
return (0, Slice_1.compositeSliceContentWithDefaultValues)(customType, content);
|
|
43
|
+
}
|
|
44
|
+
if (customType.type === "Group" &&
|
|
45
|
+
(0, GroupContent_1.isGroupContent)(content) &&
|
|
46
|
+
((_a = customType.config) === null || _a === void 0 ? void 0 : _a.fields)) {
|
|
47
|
+
const updateGroupFieldValue = (0, withDefaultValues_1.repeatableContentWithDefaultNestableContentValues)(customType.config.fields, content.value);
|
|
48
|
+
return {
|
|
49
|
+
...content,
|
|
50
|
+
value: updateGroupFieldValue,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
// Note - SimpleSliceContent can also be a NestableContent, but in that case we have no default value to fill, because the content is already there.
|
|
54
|
+
// There is no key specified in custom type that does not have a value provided like in other cases.
|
|
55
|
+
return content;
|
|
56
|
+
}
|
|
57
|
+
exports.sliceItemContentWithDefaultValues = sliceItemContentWithDefaultValues;
|
|
35
58
|
const itemLegacyReader = t.exact(t.intersection([
|
|
36
59
|
t.type({
|
|
37
60
|
key: t.string,
|
|
@@ -6199,6 +6199,7 @@ export declare const SlicesContent: t.TypeC<{
|
|
|
6199
6199
|
}>>;
|
|
6200
6200
|
}>;
|
|
6201
6201
|
export declare type SlicesContent = t.TypeOf<typeof SlicesContent>;
|
|
6202
|
+
export declare function slicesContentWithDefaultValues(codec: StaticSlices, content: SlicesContent): SlicesContent;
|
|
6202
6203
|
export declare function traverseSlices({ path, key, model, content, }: {
|
|
6203
6204
|
path: ContentPath;
|
|
6204
6205
|
key: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.traverseSlices = exports.SlicesContent = exports.SlicesLegacy = exports.isSlicesContent = exports.SlicesContentType = void 0;
|
|
3
|
+
exports.traverseSlices = exports.slicesContentWithDefaultValues = exports.SlicesContent = exports.SlicesLegacy = exports.isSlicesContent = exports.SlicesContentType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const fp_ts_1 = require("fp-ts");
|
|
6
6
|
const function_1 = require("fp-ts/lib/function");
|
|
@@ -37,6 +37,28 @@ exports.SlicesContent = t.type({
|
|
|
37
37
|
__TYPE__: t.literal(exports.SlicesContentType),
|
|
38
38
|
value: t.array(SliceItem_1.SliceItemContent),
|
|
39
39
|
});
|
|
40
|
+
function slicesContentWithDefaultValues(codec, content) {
|
|
41
|
+
var _a;
|
|
42
|
+
const choices = (_a = codec === null || codec === void 0 ? void 0 : codec.config) === null || _a === void 0 ? void 0 : _a.choices;
|
|
43
|
+
if (choices === undefined)
|
|
44
|
+
return content;
|
|
45
|
+
const updateSlicesValue = content.value.map((slice) => {
|
|
46
|
+
const sliceConfig = choices[slice.name];
|
|
47
|
+
if (sliceConfig) {
|
|
48
|
+
const updatedSliceWidget = (0, SliceItem_1.sliceItemContentWithDefaultValues)(sliceConfig, slice.widget);
|
|
49
|
+
return {
|
|
50
|
+
...slice,
|
|
51
|
+
widget: updatedSliceWidget,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return slice;
|
|
55
|
+
});
|
|
56
|
+
return {
|
|
57
|
+
...content,
|
|
58
|
+
value: updateSlicesValue,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
exports.slicesContentWithDefaultValues = slicesContentWithDefaultValues;
|
|
40
62
|
function findSliceModel(slicesPath, model, content) {
|
|
41
63
|
var _a, _b;
|
|
42
64
|
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];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { NestableWidget } from "../../customtypes";
|
|
2
|
+
import type { NestableContent } from "./nestable";
|
|
3
|
+
export declare function withDefaultNestableContentValues(customType: Record<string, NestableWidget>, content: Record<string, NestableContent>): Record<string, NestableContent>;
|
|
4
|
+
export declare function repeatableContentWithDefaultNestableContentValues<T extends {
|
|
5
|
+
value: [string, NestableContent][];
|
|
6
|
+
}>(fields: Record<string, NestableWidget>, content: T[]): T[];
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.repeatableContentWithDefaultNestableContentValues = exports.withDefaultNestableContentValues = void 0;
|
|
4
|
+
const nestable_1 = require("./nestable");
|
|
5
|
+
function withDefaultNestableContentValues(customType, content) {
|
|
6
|
+
return Object.entries(customType).reduce((updatedContent, [widgetKey, widgetDef]) => {
|
|
7
|
+
if (content[widgetKey] === undefined) {
|
|
8
|
+
const defaultValue = (0, nestable_1.NestableContentDefaultValue)(widgetDef);
|
|
9
|
+
return defaultValue !== undefined
|
|
10
|
+
? {
|
|
11
|
+
...updatedContent,
|
|
12
|
+
[widgetKey]: defaultValue,
|
|
13
|
+
}
|
|
14
|
+
: updatedContent;
|
|
15
|
+
}
|
|
16
|
+
return updatedContent;
|
|
17
|
+
}, content);
|
|
18
|
+
}
|
|
19
|
+
exports.withDefaultNestableContentValues = withDefaultNestableContentValues;
|
|
20
|
+
function repeatableContentWithDefaultNestableContentValues(fields, content) {
|
|
21
|
+
const groupKeys = Object.entries(fields);
|
|
22
|
+
return content.map((contentItem) => {
|
|
23
|
+
return groupKeys.reduce((updatedContentItem, [key, fieldDef]) => {
|
|
24
|
+
if (!contentItem.value.find(([_key]) => _key === key)) {
|
|
25
|
+
const defaultValue = (0, nestable_1.NestableContentDefaultValue)(fieldDef);
|
|
26
|
+
return {
|
|
27
|
+
...updatedContentItem,
|
|
28
|
+
value: [
|
|
29
|
+
...updatedContentItem.value,
|
|
30
|
+
...(defaultValue ? [[key, defaultValue]] : []),
|
|
31
|
+
],
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
return updatedContentItem;
|
|
35
|
+
}, contentItem);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
exports.repeatableContentWithDefaultNestableContentValues = repeatableContentWithDefaultNestableContentValues;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Asset, Embed } from "../../common";
|
|
2
|
+
import type { Document } from "../../content";
|
|
3
|
+
import type { ImportDocument } from "../validators";
|
|
4
|
+
export declare function convertImportToContent(document: ImportDocument, assets: Record<Asset["id"], Asset | undefined>, embeds: Record<string, Embed | undefined>): Document;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertImportToContent = void 0;
|
|
4
|
+
const fields_1 = require("./fields");
|
|
5
|
+
function convertImportToContent(document, assets, embeds) {
|
|
6
|
+
return Object.entries(document).reduce((acc, [fieldKey, fieldValue]) => {
|
|
7
|
+
const newFieldValue = convertWidget(fieldValue, assets, embeds);
|
|
8
|
+
return newFieldValue ? { ...acc, [fieldKey]: newFieldValue } : acc;
|
|
9
|
+
}, {});
|
|
10
|
+
}
|
|
11
|
+
exports.convertImportToContent = convertImportToContent;
|
|
12
|
+
function convertWidget(field, assets, embeds) {
|
|
13
|
+
switch (field.type) {
|
|
14
|
+
case "Slices":
|
|
15
|
+
return (0, fields_1.importSlicesConverter)(field.value, assets, embeds);
|
|
16
|
+
case "Group":
|
|
17
|
+
return (0, fields_1.importGroupConverter)(field.value, assets, embeds);
|
|
18
|
+
default:
|
|
19
|
+
return (0, fields_1.convertNestableWidget)(field, assets, embeds);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Asset, Embed } from "../../../common";
|
|
2
|
+
import type { GroupContent } from "../../../content";
|
|
3
|
+
import type { ImportGroup } from "../../validators/fields/ImportGroup";
|
|
4
|
+
export declare const importGroupConverter: (field: ImportGroup["value"], assets: Record<Asset["id"], Asset | undefined>, embeds: Record<string, Embed | undefined>) => GroupContent | undefined;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.importGroupConverter = void 0;
|
|
4
|
+
const content_1 = require("../../../content");
|
|
5
|
+
const RepeatableZone_1 = require("./RepeatableZone");
|
|
6
|
+
const importGroupConverter = (field, assets, embeds) => {
|
|
7
|
+
if (field === null)
|
|
8
|
+
return;
|
|
9
|
+
return {
|
|
10
|
+
__TYPE__: content_1.GroupContentType,
|
|
11
|
+
value: (0, RepeatableZone_1.repeatableZoneConverter)(field, assets, embeds),
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
exports.importGroupConverter = importGroupConverter;
|