@prismicio/types-internal 2.2.0-traverse.alpha-2 → 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.
- package/lib/content/Document.d.ts +13 -4
- package/lib/content/Document.js +7 -74
- package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +1 -0
- package/lib/content/fields/slices/Slice/CompositeSliceContent.js +30 -1
- package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +1 -0
- package/lib/content/fields/slices/Slice/SimpleSliceContent.js +41 -1
- package/lib/customtypes/CustomType.d.ts +5 -2
- package/lib/customtypes/CustomType.js +1 -1
- package/lib/import/converters/fields/nestable/Image.d.ts +3 -1
- package/lib/import/converters/fields/nestable/Image.js +18 -2
- package/lib/import/converters/fields/nestable/Nestable.js +2 -0
- package/lib/import/converters/fields/nestable/RichText.d.ts +4 -0
- package/lib/import/converters/fields/nestable/RichText.js +55 -0
- package/lib/import/converters/fields/nestable/index.d.ts +1 -0
- package/lib/import/converters/fields/nestable/index.js +1 -0
- package/lib/import/validators/fields/ImportField.d.ts +6 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.js +1 -1
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.js +1 -1
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.js +1 -1
- package/lib/import/validators/fields/nestable/Embed.d.ts +3 -0
- package/lib/import/validators/fields/nestable/Embed.js +3 -8
- package/lib/import/validators/fields/nestable/GeoPoint.js +2 -2
- 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 +19 -0
- package/lib/import/validators/fields/nestable/Image/index.js +22 -22
- package/lib/import/validators/fields/nestable/Image/merge.d.ts +23 -0
- package/lib/import/validators/fields/nestable/Image/{Decoder.js → merge.js} +18 -14
- package/lib/import/validators/fields/nestable/Image/{Validator.d.ts → validators.d.ts} +4 -2
- package/lib/import/validators/fields/nestable/Image/{Validator.js → validators.js} +7 -3
- 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 +26 -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 +8 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.js +11 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportTextBlock.d.ts +70 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportTextBlock.js +43 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/Span.d.ts +65 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/Span.js +20 -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/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 +17 -0
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.js +22 -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 +21 -6
- package/lib/import/validators/fields/nestable/Link.js +8 -8
- package/lib/import/validators/fields/nestable/Nestable.d.ts +8 -1
- package/lib/import/validators/fields/nestable/Nestable.js +5 -1
- package/lib/import/validators/fields/nestable/index.d.ts +2 -1
- package/lib/import/validators/fields/nestable/index.js +4 -1
- package/package.json +1 -1
- package/src/content/Document.ts +22 -98
- package/src/content/fields/slices/Slice/CompositeSliceContent.ts +37 -1
- package/src/content/fields/slices/Slice/SimpleSliceContent.ts +45 -0
- package/src/customtypes/CustomType.ts +6 -5
- package/src/import/converters/fields/nestable/Image.ts +34 -4
- package/src/import/converters/fields/nestable/Nestable.ts +3 -0
- package/src/import/converters/fields/nestable/RichText.ts +62 -0
- package/src/import/converters/fields/nestable/index.ts +1 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.ts +1 -1
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.ts +1 -1
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.ts +1 -1
- package/src/import/validators/fields/nestable/Embed.ts +4 -17
- package/src/import/validators/fields/nestable/GeoPoint.ts +2 -2
- package/src/import/validators/fields/nestable/Image/default.ts +25 -0
- package/src/import/validators/fields/nestable/Image/index.ts +34 -36
- package/src/import/validators/fields/nestable/Image/{Decoder.ts → merge.ts} +23 -20
- package/src/import/validators/fields/nestable/Image/{Validator.ts → validators.ts} +9 -2
- package/src/import/validators/fields/nestable/ImportRichText/ImportBlock.ts +39 -0
- package/src/import/validators/fields/nestable/ImportRichText/ImportRichText.ts +41 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportBlockType.ts +44 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportEmbedBlock.ts +13 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.ts +13 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportTextBlock.ts +56 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/Span.ts +44 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/index.ts +4 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/HyperlinkSpan.ts +24 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/SpanLocation.ts +8 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.ts +26 -0
- package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/index.ts +2 -0
- package/src/import/validators/fields/nestable/ImportRichText/index.ts +2 -0
- package/src/import/validators/fields/nestable/Link.ts +18 -13
- package/src/import/validators/fields/nestable/Nestable.ts +6 -1
- package/src/import/validators/fields/nestable/index.ts +2 -1
- package/lib/import/validators/fields/nestable/Image/Decoder.d.ts +0 -26
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
2
|
import { ContentPath, TraverseSliceContentFn, TraverseWidgetContentFn } from "../_internal/utils";
|
|
3
3
|
import { WidgetKey } from "../common";
|
|
4
|
-
import {
|
|
4
|
+
import { type StaticWidget } from "../customtypes";
|
|
5
5
|
import { WidgetContent } from "./fields";
|
|
6
6
|
import { FieldOrSliceType, WithTypes } from "./LegacyContentCtx";
|
|
7
7
|
export declare const Document: t.RecordC<t.Type<string, string, unknown>, t.UnionC<[t.ExactC<t.TypeC<{
|
|
@@ -2454,7 +2454,10 @@ declare function extractMetadata(data: {
|
|
|
2454
2454
|
slugs: ReadonlyArray<string>;
|
|
2455
2455
|
uid: string | undefined;
|
|
2456
2456
|
};
|
|
2457
|
-
declare function parseLegacyDocument(legacyDoc: unknown, customType:
|
|
2457
|
+
declare function parseLegacyDocument(legacyDoc: unknown, customType: {
|
|
2458
|
+
customTypeId: string;
|
|
2459
|
+
fields: Record<string, StaticWidget>;
|
|
2460
|
+
}): Document | undefined;
|
|
2458
2461
|
declare function encodeToLegacyDocument(document: Document): DocumentLegacy;
|
|
2459
2462
|
export declare const DocumentLegacy: {
|
|
2460
2463
|
_codec: (allTypes?: Map<string, "Boolean" | "Color" | "Date" | "Embed" | "GeoPoint" | "Image" | "IntegrationFields" | "Link" | "Number" | "Range" | "StructuredText" | "Select" | "Separator" | "Text" | "Timestamp" | "Group" | "Slice" | "SharedSlice" | "Choice" | "Slices" | "UID"> | undefined) => t.Type<{
|
|
@@ -4645,13 +4648,19 @@ export declare const DocumentLegacy: {
|
|
|
4645
4648
|
*/
|
|
4646
4649
|
export declare function traverseDocument({ document, model, }: {
|
|
4647
4650
|
document: Document;
|
|
4648
|
-
model?:
|
|
4651
|
+
model?: {
|
|
4652
|
+
customTypeId: string;
|
|
4653
|
+
fields: Record<string, StaticWidget>;
|
|
4654
|
+
};
|
|
4649
4655
|
}): ({ transformWidget, transformSlice, }: {
|
|
4650
4656
|
transformWidget?: TraverseWidgetContentFn;
|
|
4651
4657
|
transformSlice?: TraverseSliceContentFn;
|
|
4652
4658
|
}) => Document;
|
|
4653
4659
|
export declare function collectWidgets<W extends WidgetContent>(document: Document, is: (content: WidgetContent, path: ContentPath) => content is W): Record<string, W>;
|
|
4654
|
-
export declare function migrateDocument(document: Document,
|
|
4660
|
+
export declare function migrateDocument(document: Document, customType: {
|
|
4661
|
+
customTypeId: string;
|
|
4662
|
+
fields: Record<string, StaticWidget>;
|
|
4663
|
+
}): {
|
|
4655
4664
|
[x: string]: {
|
|
4656
4665
|
type: string;
|
|
4657
4666
|
__TYPE__: "EmptyContent";
|
package/lib/content/Document.js
CHANGED
|
@@ -103,11 +103,11 @@ exports.DocumentLegacy = {
|
|
|
103
103
|
function traverseDocument({ document, model, }) {
|
|
104
104
|
return ({ transformWidget = ({ content }) => content, transformSlice = ({ content }) => content, }) => {
|
|
105
105
|
const fieldModels = model &&
|
|
106
|
-
|
|
106
|
+
Object.entries(model.fields).reduce((acc, [key, def]) => ({ ...acc, [key]: def }), {});
|
|
107
107
|
return Object.entries(document).reduce((acc, [key, content]) => {
|
|
108
108
|
const fieldModel = fieldModels && fieldModels[key];
|
|
109
109
|
const path = utils_1.ContentPath.make([
|
|
110
|
-
{ key: model === null || model === void 0 ? void 0 : model.
|
|
110
|
+
{ key: model === null || model === void 0 ? void 0 : model.customTypeId, type: "CustomType" },
|
|
111
111
|
{ key, type: "Widget" },
|
|
112
112
|
]);
|
|
113
113
|
const transformedWidget = (() => {
|
|
@@ -171,86 +171,19 @@ function collectWidgets(document, is) {
|
|
|
171
171
|
return collected;
|
|
172
172
|
}
|
|
173
173
|
exports.collectWidgets = collectWidgets;
|
|
174
|
-
function
|
|
175
|
-
|
|
176
|
-
key: content.key,
|
|
177
|
-
name: model.sliceName,
|
|
178
|
-
maybeLabel: content.maybeLabel,
|
|
179
|
-
widget: {
|
|
180
|
-
__TYPE__: "SharedSliceContent",
|
|
181
|
-
variation: model.variationId,
|
|
182
|
-
primary: Object.entries(content.widget.nonRepeat).reduce((acc, [fieldKey, fieldContent]) => {
|
|
183
|
-
var _a;
|
|
184
|
-
return ((_a = model.fields.primary) === null || _a === void 0 ? void 0 : _a[fieldKey])
|
|
185
|
-
? { ...acc, [fieldKey]: fieldContent }
|
|
186
|
-
: acc;
|
|
187
|
-
}, {}),
|
|
188
|
-
items: content.widget.repeat.map((groupItem) => {
|
|
189
|
-
return {
|
|
190
|
-
__TYPE__: "GroupItemContent",
|
|
191
|
-
value: groupItem.value.reduce((acc, [fieldKey, fieldContent]) => {
|
|
192
|
-
var _a;
|
|
193
|
-
return ((_a = model.fields.items) === null || _a === void 0 ? void 0 : _a[fieldKey])
|
|
194
|
-
? acc.concat([[fieldKey, fieldContent]])
|
|
195
|
-
: acc;
|
|
196
|
-
}, []),
|
|
197
|
-
};
|
|
198
|
-
}, []),
|
|
199
|
-
},
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
function migrateSimpleSlice(model, content) {
|
|
203
|
-
var _a;
|
|
204
|
-
if (content.widget.__TYPE__ === "GroupContentType") {
|
|
205
|
-
return {
|
|
206
|
-
key: content.key,
|
|
207
|
-
name: model.sliceName,
|
|
208
|
-
maybeLabel: content.maybeLabel,
|
|
209
|
-
widget: {
|
|
210
|
-
__TYPE__: "SharedSliceContent",
|
|
211
|
-
variation: model.variationId,
|
|
212
|
-
primary: {},
|
|
213
|
-
items: content.widget.value.map((groupItem) => {
|
|
214
|
-
return {
|
|
215
|
-
__TYPE__: "GroupItemContent",
|
|
216
|
-
value: groupItem.value.reduce((acc, [fieldKey, fieldContent]) => {
|
|
217
|
-
var _a;
|
|
218
|
-
return ((_a = model.fields.items) === null || _a === void 0 ? void 0 : _a[fieldKey])
|
|
219
|
-
? acc.concat([[fieldKey, fieldContent]])
|
|
220
|
-
: acc;
|
|
221
|
-
}, []),
|
|
222
|
-
};
|
|
223
|
-
}, []),
|
|
224
|
-
},
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
return {
|
|
228
|
-
key: content.key,
|
|
229
|
-
name: model.sliceName,
|
|
230
|
-
maybeLabel: content.maybeLabel,
|
|
231
|
-
widget: {
|
|
232
|
-
__TYPE__: "SharedSliceContent",
|
|
233
|
-
variation: model.variationId,
|
|
234
|
-
primary: ((_a = model.fields.primary) === null || _a === void 0 ? void 0 : _a[content.name])
|
|
235
|
-
? { [content.key]: content.widget }
|
|
236
|
-
: {},
|
|
237
|
-
items: [],
|
|
238
|
-
},
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
function migrateDocument(document, model) {
|
|
242
|
-
const needsMigration = Object.values((0, customtypes_1.collectSharedSlices)(model)).some((slice) => Boolean(slice.legacyPaths));
|
|
174
|
+
function migrateDocument(document, customType) {
|
|
175
|
+
const needsMigration = Object.values((0, customtypes_1.collectSharedSlices)(customType)).some((slice) => Boolean(slice.legacyPaths));
|
|
243
176
|
if (!needsMigration)
|
|
244
177
|
return document;
|
|
245
178
|
return traverseDocument({
|
|
246
179
|
document,
|
|
247
|
-
model,
|
|
180
|
+
model: customType,
|
|
248
181
|
})({
|
|
249
182
|
transformSlice: ({ content, model }) => {
|
|
250
183
|
if ((0, fields_1.isCompositeSliceItemContent)(content) && (model === null || model === void 0 ? void 0 : model.type) === "SharedSlice")
|
|
251
|
-
return migrateCompositeSlice(model, content);
|
|
184
|
+
return (0, fields_1.migrateCompositeSlice)(model, content);
|
|
252
185
|
if ((0, fields_1.isSimpleSliceItemContent)(content) && (model === null || model === void 0 ? void 0 : model.type) === "SharedSlice")
|
|
253
|
-
return migrateSimpleSlice(model, content);
|
|
186
|
+
return (0, fields_1.migrateSimpleSlice)(model, content);
|
|
254
187
|
return content;
|
|
255
188
|
},
|
|
256
189
|
});
|
|
@@ -1709,3 +1709,4 @@ export declare function traverseCompositeSliceContent({ path, sliceKey, sliceNam
|
|
|
1709
1709
|
content: CompositeSliceItemContent;
|
|
1710
1710
|
model?: VariationFields | CompositeSliceFields | undefined;
|
|
1711
1711
|
}): (transformWidget: TraverseWidgetContentFn, transformSlice: TraverseSliceContentFn) => SharedSliceItemContent | CompositeSliceItemContent | undefined;
|
|
1712
|
+
export declare function migrateCompositeSlice(model: VariationFields, content: CompositeSliceItemContent): SharedSliceItemContent;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.traverseCompositeSliceContent = exports.CompositeSliceContent = exports.CompositeSliceLegacy = exports.isCompositeSliceContent = exports.CompositeSliceContentType = void 0;
|
|
3
|
+
exports.migrateCompositeSlice = exports.traverseCompositeSliceContent = 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");
|
|
@@ -131,3 +131,32 @@ function traverseCompositeSliceContent({ path, sliceKey, sliceName, model, conte
|
|
|
131
131
|
};
|
|
132
132
|
}
|
|
133
133
|
exports.traverseCompositeSliceContent = traverseCompositeSliceContent;
|
|
134
|
+
function migrateCompositeSlice(model, content) {
|
|
135
|
+
return {
|
|
136
|
+
key: content.key,
|
|
137
|
+
name: model.sliceName,
|
|
138
|
+
maybeLabel: content.maybeLabel,
|
|
139
|
+
widget: {
|
|
140
|
+
__TYPE__: "SharedSliceContent",
|
|
141
|
+
variation: model.variationId,
|
|
142
|
+
primary: Object.entries(content.widget.nonRepeat).reduce((acc, [fieldKey, fieldContent]) => {
|
|
143
|
+
var _a;
|
|
144
|
+
return ((_a = model.fields.primary) === null || _a === void 0 ? void 0 : _a[fieldKey])
|
|
145
|
+
? { ...acc, [fieldKey]: fieldContent }
|
|
146
|
+
: acc;
|
|
147
|
+
}, {}),
|
|
148
|
+
items: content.widget.repeat.map((groupItem) => {
|
|
149
|
+
return {
|
|
150
|
+
__TYPE__: "GroupItemContent",
|
|
151
|
+
value: groupItem.value.reduce((acc, [fieldKey, fieldContent]) => {
|
|
152
|
+
var _a;
|
|
153
|
+
return ((_a = model.fields.items) === null || _a === void 0 ? void 0 : _a[fieldKey])
|
|
154
|
+
? acc.concat([[fieldKey, fieldContent]])
|
|
155
|
+
: acc;
|
|
156
|
+
}, []),
|
|
157
|
+
};
|
|
158
|
+
}, []),
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
exports.migrateCompositeSlice = migrateCompositeSlice;
|
|
@@ -1699,3 +1699,4 @@ export declare function traverseSimpleSliceContent({ path, sliceKey, sliceName,
|
|
|
1699
1699
|
content: SimpleSliceItemContent;
|
|
1700
1700
|
model?: VariationFields | Group | NestableWidget | undefined;
|
|
1701
1701
|
}): (transformWidget: TraverseWidgetContentFn, transformSlice: TraverseSliceContentFn) => SharedSliceItemContent | SimpleSliceItemContent | undefined;
|
|
1702
|
+
export declare function migrateSimpleSlice(model: VariationFields, content: SimpleSliceItemContent): SharedSliceItemContent;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.traverseSimpleSliceContent = exports.SimpleSliceLegacy = exports.isSimpleSliceContent = exports.SimpleSliceContent = void 0;
|
|
3
|
+
exports.migrateSimpleSlice = exports.traverseSimpleSliceContent = exports.SimpleSliceLegacy = exports.isSimpleSliceContent = exports.SimpleSliceContent = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
6
|
const GroupContent_1 = require("../../GroupContent");
|
|
@@ -85,3 +85,43 @@ function traverseSimpleSliceContent({ path, sliceKey, sliceName, model, content,
|
|
|
85
85
|
};
|
|
86
86
|
}
|
|
87
87
|
exports.traverseSimpleSliceContent = traverseSimpleSliceContent;
|
|
88
|
+
function migrateSimpleSlice(model, content) {
|
|
89
|
+
var _a;
|
|
90
|
+
if (content.widget.__TYPE__ === "GroupContentType") {
|
|
91
|
+
return {
|
|
92
|
+
key: content.key,
|
|
93
|
+
name: model.sliceName,
|
|
94
|
+
maybeLabel: content.maybeLabel,
|
|
95
|
+
widget: {
|
|
96
|
+
__TYPE__: "SharedSliceContent",
|
|
97
|
+
variation: model.variationId,
|
|
98
|
+
primary: {},
|
|
99
|
+
items: content.widget.value.map((groupItem) => {
|
|
100
|
+
return {
|
|
101
|
+
__TYPE__: "GroupItemContent",
|
|
102
|
+
value: groupItem.value.reduce((acc, [fieldKey, fieldContent]) => {
|
|
103
|
+
var _a;
|
|
104
|
+
return ((_a = model.fields.items) === null || _a === void 0 ? void 0 : _a[fieldKey])
|
|
105
|
+
? acc.concat([[fieldKey, fieldContent]])
|
|
106
|
+
: acc;
|
|
107
|
+
}, []),
|
|
108
|
+
};
|
|
109
|
+
}, []),
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
key: content.key,
|
|
115
|
+
name: model.sliceName,
|
|
116
|
+
maybeLabel: content.maybeLabel,
|
|
117
|
+
widget: {
|
|
118
|
+
__TYPE__: "SharedSliceContent",
|
|
119
|
+
variation: model.variationId,
|
|
120
|
+
primary: ((_a = model.fields.primary) === null || _a === void 0 ? void 0 : _a[content.name])
|
|
121
|
+
? { [content.key]: content.widget }
|
|
122
|
+
: {},
|
|
123
|
+
items: [],
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
exports.migrateSimpleSlice = migrateSimpleSlice;
|
|
@@ -2398,6 +2398,9 @@ export declare function toStatic(customType: CustomType, sharedSlices: Map<strin
|
|
|
2398
2398
|
export declare function validateSlices(customType: CustomType, sharedSlices: Map<string, SharedSlice>): Either<CustomTypeSlicesError, CustomType>;
|
|
2399
2399
|
export declare function collectWidgets(customType: CustomType, f: (ref: string, widget: DynamicWidget) => DynamicWidget | undefined): CustomType;
|
|
2400
2400
|
export declare function filterMissingSharedSlices(customType: CustomType, sharedSlices: Map<string, SharedSlice>): CustomType;
|
|
2401
|
-
export declare function flattenCustomTypeFields(customType: StaticCustomType):
|
|
2402
|
-
export declare function collectSharedSlices(customType:
|
|
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>;
|
|
2403
2406
|
export {};
|
|
@@ -148,7 +148,7 @@ function flattenCustomTypeFields(customType) {
|
|
|
148
148
|
}
|
|
149
149
|
exports.flattenCustomTypeFields = flattenCustomTypeFields;
|
|
150
150
|
function collectSharedSlices(customType) {
|
|
151
|
-
return
|
|
151
|
+
return Object.entries(customType.fields).reduce((acc, [, w]) => {
|
|
152
152
|
var _a;
|
|
153
153
|
if (w.type === "Slices" || w.type === "Choice") {
|
|
154
154
|
return {
|
|
@@ -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(
|
|
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;
|
|
@@ -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.
|
|
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.
|
|
15
|
+
const SharedSliceTypeShape = t.strict({
|
|
16
16
|
slice_type: validators_1.NonEmptyString,
|
|
17
17
|
slice: customtypes_1.SharedSlice,
|
|
18
18
|
});
|
package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.js
CHANGED
|
@@ -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.
|
|
15
|
+
const SharedSliceVariationShape = t.strict({
|
|
16
16
|
variation: validators_1.NonEmptyString,
|
|
17
17
|
data: customtypes_1.Variation,
|
|
18
18
|
});
|
|
@@ -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
|
-
|
|
28
|
+
exports.ImportEmbedValue = t.strict({
|
|
31
29
|
embed_url: EmbedUrl,
|
|
32
30
|
});
|
|
33
|
-
|
|
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));
|
|
@@ -6,8 +6,8 @@ const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
|
6
6
|
const validators_1 = require("../../../../validators");
|
|
7
7
|
const function_1 = require("../../../../validators/function");
|
|
8
8
|
const ImportContent_1 = require("../ImportContent");
|
|
9
|
-
const
|
|
9
|
+
const GeoPoint = (0, function_1.withCustomError)(t.strict({
|
|
10
10
|
latitude: (0, validators_1.NumberRange)(-90, 90, "latitude"),
|
|
11
11
|
longitude: (0, validators_1.NumberRange)(-180, 180, "longitude"),
|
|
12
12
|
}), () => "GeoPoint must be an object with the properties `latitude` and `longitude` between the given ranges");
|
|
13
|
-
exports.ImportGeoPoint = (0, ImportContent_1.ImportContent)("GeoPoint", (0, validators_1.EmptyObjectOrElse)(
|
|
13
|
+
exports.ImportGeoPoint = (0, ImportContent_1.ImportContent)("GeoPoint", (0, validators_1.EmptyObjectOrElse)(GeoPoint));
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as t from "io-ts";
|
|
2
|
+
export declare const defaultImportImage: (field?: ({
|
|
3
|
+
type: "Image";
|
|
4
|
+
} & {
|
|
5
|
+
fieldset?: string | null | undefined;
|
|
6
|
+
config?: {
|
|
7
|
+
label?: string | null | undefined;
|
|
8
|
+
placeholder?: string;
|
|
9
|
+
constraint?: {
|
|
10
|
+
width?: number | null;
|
|
11
|
+
height?: number | null;
|
|
12
|
+
};
|
|
13
|
+
thumbnails?: readonly ({
|
|
14
|
+
name: string;
|
|
15
|
+
} & {
|
|
16
|
+
width?: number | null;
|
|
17
|
+
height?: number | null;
|
|
18
|
+
})[];
|
|
19
|
+
};
|
|
20
|
+
}) | undefined) => t.Type<Record<never, never>, {
|
|
21
|
+
[key: string]: unknown;
|
|
22
|
+
}, unknown>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defaultImportImage = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
|
+
const validators_1 = require("../../../../../validators");
|
|
7
|
+
const function_1 = require("../../../../../validators/function");
|
|
8
|
+
const defaultImportImage = (field) => {
|
|
9
|
+
var _a;
|
|
10
|
+
// If there is not thumbnails we expect an empty object
|
|
11
|
+
if (!((_a = field === null || field === void 0 ? void 0 : field.config) === null || _a === void 0 ? void 0 : _a.thumbnails) || !field.config.thumbnails.length)
|
|
12
|
+
return validators_1.EmptyObject;
|
|
13
|
+
// If there are thumbnails, we expect an object with thumbnails as empty objects
|
|
14
|
+
return (0, function_1.withCustomError)(t.strict(field.config.thumbnails.reduce((acc, thumbnail) => ({
|
|
15
|
+
...acc,
|
|
16
|
+
[thumbnail.name]: validators_1.EmptyObject,
|
|
17
|
+
}), {})), () => "The value must be an object");
|
|
18
|
+
};
|
|
19
|
+
exports.defaultImportImage = defaultImportImage;
|
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
2
|
import type { ImageFieldWithThumbnails } from "./model";
|
|
3
|
+
export declare const ImageFieldCodec: (field?: ({
|
|
4
|
+
type: "Image";
|
|
5
|
+
} & {
|
|
6
|
+
fieldset?: string | null | undefined;
|
|
7
|
+
config?: {
|
|
8
|
+
label?: string | null | undefined;
|
|
9
|
+
placeholder?: string;
|
|
10
|
+
constraint?: {
|
|
11
|
+
width?: number | null;
|
|
12
|
+
height?: number | null;
|
|
13
|
+
};
|
|
14
|
+
thumbnails?: readonly ({
|
|
15
|
+
name: string;
|
|
16
|
+
} & {
|
|
17
|
+
width?: number | null;
|
|
18
|
+
height?: number | null;
|
|
19
|
+
})[];
|
|
20
|
+
};
|
|
21
|
+
}) | undefined) => t.Type<ImageFieldWithThumbnails, ImageFieldWithThumbnails, unknown>;
|
|
3
22
|
export declare const ImportImage: (field?: ({
|
|
4
23
|
type: "Image";
|
|
5
24
|
} & {
|