@prismicio/types-internal 2.2.0-traverse.alpha-6 → 2.2.0-traverse.alpha-7
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/_internal/utils.d.ts +3 -3
- package/lib/content/Document.d.ts +1248 -32
- package/lib/content/fields/GroupContent.d.ts +273 -7
- package/lib/content/fields/WidgetContent.d.ts +1248 -32
- package/lib/content/fields/nestable/NestableContent.d.ts +156 -4
- package/lib/content/fields/nestable/RichTextContent/Blocks.d.ts +582 -28
- package/lib/content/fields/nestable/RichTextContent/Blocks.js +29 -46
- package/lib/content/fields/nestable/RichTextContent/index.d.ts +195 -5
- package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +314 -10
- package/lib/content/fields/slices/Slice/CompositeSliceContent.js +3 -5
- package/lib/content/fields/slices/Slice/RepeatableContent.d.ts +117 -3
- package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +312 -8
- package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +312 -8
- package/lib/content/fields/slices/Slice/index.d.ts +702 -18
- package/lib/content/fields/slices/SliceItem.d.ts +702 -18
- package/lib/content/fields/slices/SlicesContent.d.ts +936 -24
- package/lib/content/fields/slices/SlicesContent.js +2 -4
- package/lib/customtypes/widgets/slices/CompositeSlice.d.ts +0 -5
- 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 +25 -3
- package/lib/import/converters/fields/nestable/Image.js +21 -25
- 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 +41 -0
- package/lib/import/converters/fields/nestable/index.d.ts +1 -1
- package/lib/import/converters/fields/nestable/index.js +1 -1
- package/lib/import/validators/fields/ImportContent.js +3 -3
- package/lib/import/validators/fields/ImportField.d.ts +1 -1
- package/lib/import/validators/fields/ImportSlices/ImportSlices.js +4 -3
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.js +1 -1
- package/lib/import/validators/fields/nestable/ImportRichText/ImportRichText.d.ts +1 -1
- package/lib/import/validators/fields/nestable/ImportRichText/ImportRichText.js +20 -14
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.d.ts +16 -2
- package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.js +7 -5
- package/lib/import/validators/fields/nestable/Nestable.d.ts +1 -1
- package/lib/validators/DefaultOrElse.js +3 -3
- package/package.json +1 -1
- package/src/_internal/utils.ts +3 -3
- package/src/content/fields/nestable/RichTextContent/Blocks.ts +48 -58
- package/src/content/fields/slices/Slice/CompositeSliceContent.ts +4 -9
- package/src/content/fields/slices/SlicesContent.ts +4 -6
- package/src/customtypes/widgets/slices/CompositeSlice.ts +0 -6
- package/src/import/converters/fields/nestable/Image.ts +10 -22
- package/src/import/converters/fields/nestable/RichText/embedBlock.ts +17 -0
- package/src/import/converters/fields/nestable/RichText/imageBlock.ts +17 -0
- package/src/import/converters/fields/nestable/RichText/index.ts +23 -0
- package/src/import/converters/fields/nestable/RichText/textBlock.ts +48 -0
- package/src/import/converters/fields/nestable/index.ts +1 -1
- package/src/import/validators/fields/ImportContent.ts +3 -3
- package/src/import/validators/fields/ImportSlices/ImportSlices.ts +7 -5
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.ts +1 -1
- package/src/import/validators/fields/nestable/ImportRichText/ImportRichText.ts +38 -25
- package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.ts +9 -5
- package/src/validators/DefaultOrElse.ts +4 -4
- package/src/import/converters/fields/nestable/RichText.ts +0 -62
- /package/src/import/converters/fields/nestable/{GeooPoint.ts → GeoPoint.ts} +0 -0
|
@@ -91,10 +91,8 @@ function findSliceModel(slicesPath, model, content) {
|
|
|
91
91
|
if ((0, customtypes_1.isCompositeSlice)(defaultModel)) {
|
|
92
92
|
return {
|
|
93
93
|
type: "Slice",
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
repeat: defaultModel.repeat || {},
|
|
97
|
-
},
|
|
94
|
+
"non-repeat": defaultModel["non-repeat"] || {},
|
|
95
|
+
repeat: defaultModel.repeat || {},
|
|
98
96
|
};
|
|
99
97
|
}
|
|
100
98
|
if ((0, customtypes_1.isLegacySlice)(defaultModel)) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
|
-
import type { PickOnly } from "../../../_internal/utils";
|
|
3
2
|
import type { DynamicSlice, StaticSlice } from "./Slice";
|
|
4
3
|
export declare const CompositeSliceType = "Slice";
|
|
5
4
|
export declare const CompositeSliceConfig: t.ExactC<t.PartialC<{
|
|
@@ -332,8 +331,4 @@ export declare const CompositeSlice: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
|
332
331
|
}>>;
|
|
333
332
|
}>]>>;
|
|
334
333
|
export declare type CompositeSlice = t.TypeOf<typeof CompositeSlice>;
|
|
335
|
-
export declare type CompositeSliceFields = {
|
|
336
|
-
type: "Slice";
|
|
337
|
-
fields: PickOnly<CompositeSlice, "non-repeat" | "repeat">;
|
|
338
|
-
};
|
|
339
334
|
export declare function isCompositeSlice(slice: DynamicSlice | StaticSlice): slice is CompositeSlice;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.geopointConverter = void 0;
|
|
4
|
+
const geopointConverter = (field) => {
|
|
5
|
+
if (field === null)
|
|
6
|
+
return;
|
|
7
|
+
return {
|
|
8
|
+
position: {
|
|
9
|
+
lat: field.latitude,
|
|
10
|
+
lng: field.longitude,
|
|
11
|
+
},
|
|
12
|
+
__TYPE__: "GeoPointContent",
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
exports.geopointConverter = geopointConverter;
|
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
import type { Asset } from "../../../../common";
|
|
2
|
-
import type { ImageContent
|
|
3
|
-
import type { ImportImage } from "../../../validators";
|
|
2
|
+
import type { ImageContent } from "../../../../content";
|
|
3
|
+
import type { ImageField, ImportImage } from "../../../validators";
|
|
4
4
|
import type { ImportImageBlock } from "../../../validators/fields/nestable/ImportRichText/blocks";
|
|
5
|
-
export declare
|
|
5
|
+
export declare function convertImageView<Input extends ImageField | ImportImageBlock>(inputImage: Input, image: Asset): {
|
|
6
|
+
origin: {
|
|
7
|
+
id: string;
|
|
8
|
+
url: string;
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
};
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
edit: {
|
|
15
|
+
zoom: number;
|
|
16
|
+
crop: {
|
|
17
|
+
x: number;
|
|
18
|
+
y: number;
|
|
19
|
+
};
|
|
20
|
+
background: string;
|
|
21
|
+
};
|
|
22
|
+
} & {
|
|
23
|
+
url?: string;
|
|
24
|
+
credits?: string | null;
|
|
25
|
+
alt?: string | null;
|
|
26
|
+
provider?: string | null | undefined;
|
|
27
|
+
};
|
|
6
28
|
export declare const imageConverter: (imageField: ImportImage["value"], assets: Record<Asset["id"], Asset | undefined>) => ImageContent | undefined;
|
|
@@ -1,43 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.imageConverter = exports.
|
|
3
|
+
exports.imageConverter = exports.convertImageView = void 0;
|
|
4
4
|
const common_1 = require("../../../../common");
|
|
5
5
|
const Objects_1 = require("../../../../utils/Objects");
|
|
6
|
-
function
|
|
7
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
6
|
+
function convertImageView(inputImage, image) {
|
|
7
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
8
8
|
// We can do that because anyway all properties being read
|
|
9
9
|
const imageField = {
|
|
10
10
|
...inputImage,
|
|
11
|
-
edit:
|
|
12
|
-
|
|
13
|
-
:
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
dimensions: "dimensions" in inputImage ? inputImage.dimensions : {},
|
|
11
|
+
edit: {
|
|
12
|
+
x: 0,
|
|
13
|
+
y: 0,
|
|
14
|
+
zoom: 1,
|
|
15
|
+
...inputImage.edit,
|
|
16
|
+
},
|
|
17
|
+
dimensions: (_a = inputImage.dimensions) !== null && _a !== void 0 ? _a : {},
|
|
19
18
|
};
|
|
20
19
|
return (0, Objects_1.withOptionals)({
|
|
21
20
|
origin: {
|
|
22
21
|
id: image.id,
|
|
23
22
|
url: image.origin_url,
|
|
24
23
|
// All images returned form Asset API should have width and height properties.
|
|
25
|
-
width: (
|
|
26
|
-
height: (
|
|
24
|
+
width: (_b = image.width) !== null && _b !== void 0 ? _b : 0,
|
|
25
|
+
height: (_c = image.height) !== null && _c !== void 0 ? _c : 0,
|
|
27
26
|
},
|
|
28
27
|
// All images returned form Asset API should have width and height properties.
|
|
29
28
|
// Image width and height will be only applied if there are no constraints and user didn't overwrite it
|
|
30
|
-
width: (
|
|
31
|
-
height: (
|
|
29
|
+
width: (_f = (_e = (_d = imageField === null || imageField === void 0 ? void 0 : imageField.dimensions) === null || _d === void 0 ? void 0 : _d.width) !== null && _e !== void 0 ? _e : image.width) !== null && _f !== void 0 ? _f : 0,
|
|
30
|
+
height: (_j = (_h = (_g = imageField === null || imageField === void 0 ? void 0 : imageField.dimensions) === null || _g === void 0 ? void 0 : _g.height) !== null && _h !== void 0 ? _h : image.height) !== null && _j !== void 0 ? _j : 0,
|
|
32
31
|
// If edit is not provided, we crop constraint width and height from the left upper corner.
|
|
33
32
|
// WARN: If constraints are greater than image dimensions cut outside the image (background will fill extra space).
|
|
34
33
|
edit: {
|
|
35
|
-
zoom: (
|
|
34
|
+
zoom: (_l = (_k = imageField.edit) === null || _k === void 0 ? void 0 : _k.zoom) !== null && _l !== void 0 ? _l : 1,
|
|
36
35
|
crop: {
|
|
37
|
-
x: (
|
|
38
|
-
y: (
|
|
36
|
+
x: (_o = (_m = imageField.edit) === null || _m === void 0 ? void 0 : _m.x) !== null && _o !== void 0 ? _o : 0,
|
|
37
|
+
y: (_q = (_p = imageField.edit) === null || _p === void 0 ? void 0 : _p.y) !== null && _q !== void 0 ? _q : 0,
|
|
39
38
|
},
|
|
40
|
-
background: (
|
|
39
|
+
background: (_s = (_r = imageField.edit) === null || _r === void 0 ? void 0 : _r.background) !== null && _s !== void 0 ? _s : (image.extension === "png" ? "transparent" : "#ffffff"),
|
|
41
40
|
},
|
|
42
41
|
url: image.url,
|
|
43
42
|
}, [
|
|
@@ -45,25 +44,22 @@ function convertImage(inputImage, image) {
|
|
|
45
44
|
["credits", (imageField === null || imageField === void 0 ? void 0 : imageField.copyright) || image.credits],
|
|
46
45
|
]);
|
|
47
46
|
}
|
|
47
|
+
exports.convertImageView = convertImageView;
|
|
48
48
|
function convertThumbnails(imageField, assets) {
|
|
49
49
|
return Object.entries(imageField.thumbnails).reduce((acc, [thumbnailName, thumbnail]) => {
|
|
50
50
|
return {
|
|
51
51
|
...acc,
|
|
52
|
-
[thumbnailName]:
|
|
52
|
+
[thumbnailName]: convertImageView(thumbnail, (0, common_1.getAssetOrThrow)(assets)(thumbnail.id)),
|
|
53
53
|
};
|
|
54
54
|
}, {});
|
|
55
55
|
}
|
|
56
|
-
const imageBlockConverter = (imageBlock, assets) => {
|
|
57
|
-
return convertImage(imageBlock, (0, common_1.getAssetOrThrow)(assets)(imageBlock.id));
|
|
58
|
-
};
|
|
59
|
-
exports.imageBlockConverter = imageBlockConverter;
|
|
60
56
|
// All assets from `imageField` must be present in `assets`
|
|
61
57
|
// If not then function will throw an error
|
|
62
58
|
const imageConverter = (imageField, assets) => {
|
|
63
59
|
if (!imageField)
|
|
64
60
|
return;
|
|
65
61
|
return {
|
|
66
|
-
...
|
|
62
|
+
...convertImageView(imageField, (0, common_1.getAssetOrThrow)(assets)(imageField.id)),
|
|
67
63
|
thumbnails: convertThumbnails(imageField, assets),
|
|
68
64
|
__TYPE__: "ImageContent",
|
|
69
65
|
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Embed } from "../../../../../common";
|
|
2
|
+
import type { EmbedBlock } from "../../../../../content";
|
|
3
|
+
import type { ImportEmbedBlock } from "../../../../validators/fields/nestable/ImportRichText/blocks";
|
|
4
|
+
export declare function embedBlockConverter(block: ImportEmbedBlock, embeds: Record<string, Embed | undefined>): EmbedBlock;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.embedBlockConverter = void 0;
|
|
4
|
+
const Embed_1 = require("../Embed");
|
|
5
|
+
function embedBlockConverter(block, embeds) {
|
|
6
|
+
const embedData = (0, Embed_1.embedConverter)(block.oembed, embeds);
|
|
7
|
+
if (!embedData)
|
|
8
|
+
throw new Error("Failed to convert embed data");
|
|
9
|
+
return {
|
|
10
|
+
type: block.type,
|
|
11
|
+
data: embedData,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
exports.embedBlockConverter = embedBlockConverter;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Asset } from "../../../../../common";
|
|
2
|
+
import type { ImageBlock } from "../../../../../content";
|
|
3
|
+
import type { ImportImageBlock } from "../../../../validators/fields/nestable/ImportRichText/blocks";
|
|
4
|
+
export declare function imageBlockConverter(block: ImportImageBlock, assets: Record<Asset["id"], Asset | undefined>): ImageBlock;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.imageBlockConverter = void 0;
|
|
4
|
+
const common_1 = require("../../../../../common");
|
|
5
|
+
const Image_1 = require("../Image");
|
|
6
|
+
function imageBlockConverter(block, assets) {
|
|
7
|
+
return {
|
|
8
|
+
type: block.type,
|
|
9
|
+
data: (0, Image_1.convertImageView)(block, (0, common_1.getAssetOrThrow)(assets)(block.id)),
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
exports.imageBlockConverter = imageBlockConverter;
|
|
@@ -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,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.richTextConverter = void 0;
|
|
4
|
+
const content_1 = require("../../../../../content");
|
|
5
|
+
const embedBlock_1 = require("./embedBlock");
|
|
6
|
+
const imageBlock_1 = require("./imageBlock");
|
|
7
|
+
const textBlock_1 = require("./textBlock");
|
|
8
|
+
const richTextConverter = (richTextField, assets, embeds) => {
|
|
9
|
+
if (richTextField === null)
|
|
10
|
+
return;
|
|
11
|
+
return {
|
|
12
|
+
__TYPE__: content_1.RichTextContentType,
|
|
13
|
+
value: richTextField.map((block) => {
|
|
14
|
+
if (block.type === "image")
|
|
15
|
+
return (0, imageBlock_1.imageBlockConverter)(block, assets);
|
|
16
|
+
else if (block.type === "embed")
|
|
17
|
+
return (0, embedBlock_1.embedBlockConverter)(block, embeds);
|
|
18
|
+
return (0, textBlock_1.textBlockConverter)(block, assets);
|
|
19
|
+
}),
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
exports.richTextConverter = richTextConverter;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Asset } from "../../../../../common";
|
|
2
|
+
import type { TextBlock } from "../../../../../content";
|
|
3
|
+
import type { ImportTextBlock } from "../../../../validators/fields/nestable/ImportRichText/blocks";
|
|
4
|
+
export declare function textBlockConverter(block: ImportTextBlock, assets: Record<Asset["id"], Asset | undefined>): TextBlock;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.textBlockConverter = void 0;
|
|
4
|
+
const Link_1 = require("../Link");
|
|
5
|
+
function textBlockConverter(block, assets) {
|
|
6
|
+
return {
|
|
7
|
+
type: block.type,
|
|
8
|
+
content: {
|
|
9
|
+
text: block.text,
|
|
10
|
+
...(() => {
|
|
11
|
+
if (block.spans) {
|
|
12
|
+
const convertedSpans = spansConverter(block.spans, assets);
|
|
13
|
+
if (!convertedSpans)
|
|
14
|
+
return {};
|
|
15
|
+
return { spans: convertedSpans };
|
|
16
|
+
}
|
|
17
|
+
return {};
|
|
18
|
+
})(),
|
|
19
|
+
},
|
|
20
|
+
...(block.direction ? { direction: block.direction } : {}),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
exports.textBlockConverter = textBlockConverter;
|
|
24
|
+
function spansConverter(spans, assets) {
|
|
25
|
+
return spans.map((span) => {
|
|
26
|
+
return {
|
|
27
|
+
type: span.type,
|
|
28
|
+
start: span.start,
|
|
29
|
+
end: span.end,
|
|
30
|
+
...(() => {
|
|
31
|
+
if (span.type === "hyperlink") {
|
|
32
|
+
const convertedLinkContent = (0, Link_1.linkConverter)(span.data, assets);
|
|
33
|
+
if (!convertedLinkContent)
|
|
34
|
+
return {};
|
|
35
|
+
return { data: convertedLinkContent === null || convertedLinkContent === void 0 ? void 0 : convertedLinkContent.value };
|
|
36
|
+
}
|
|
37
|
+
return {};
|
|
38
|
+
})(),
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
}
|
|
@@ -5,7 +5,7 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
(0, tslib_1.__exportStar)(require("./Color"), exports);
|
|
6
6
|
(0, tslib_1.__exportStar)(require("./Date"), exports);
|
|
7
7
|
(0, tslib_1.__exportStar)(require("./Embed"), exports);
|
|
8
|
-
(0, tslib_1.__exportStar)(require("./
|
|
8
|
+
(0, tslib_1.__exportStar)(require("./GeoPoint"), exports);
|
|
9
9
|
(0, tslib_1.__exportStar)(require("./Image"), exports);
|
|
10
10
|
(0, tslib_1.__exportStar)(require("./Link"), exports);
|
|
11
11
|
(0, tslib_1.__exportStar)(require("./Nestable"), exports);
|
|
@@ -6,12 +6,12 @@ const fp_ts_1 = require("fp-ts");
|
|
|
6
6
|
const function_1 = require("fp-ts/lib/function");
|
|
7
7
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
8
8
|
const Objects_1 = require("../../../utils/Objects");
|
|
9
|
-
const ImportContent = (type, valueCodec) => new t.Type(
|
|
9
|
+
const ImportContent = (type, valueCodec) => new t.Type(`ImportField: ${valueCodec.name}`, (u) => {
|
|
10
10
|
if (!(0, Objects_1.isObject)(u))
|
|
11
11
|
return false;
|
|
12
12
|
return type === u["type"] && valueCodec.is(u["value"]);
|
|
13
|
-
}, (u) => {
|
|
14
|
-
return (0, function_1.pipe)(valueCodec.
|
|
13
|
+
}, (u, c) => {
|
|
14
|
+
return (0, function_1.pipe)(valueCodec.validate(u, c), fp_ts_1.either.map((decodedValue) => {
|
|
15
15
|
return {
|
|
16
16
|
type,
|
|
17
17
|
value: decodedValue,
|
|
@@ -52,7 +52,7 @@ export declare const ImportField: {
|
|
|
52
52
|
} | undefined, unknown> | import("io-ts").Type<{
|
|
53
53
|
type: "StructuredText";
|
|
54
54
|
value: import("./nestable").ImportBlock[] | null;
|
|
55
|
-
},
|
|
55
|
+
}, import("./nestable").ImportBlock[] | undefined, unknown> | import("io-ts").Type<{
|
|
56
56
|
type: "Number";
|
|
57
57
|
value: number | null;
|
|
58
58
|
}, number | undefined, unknown> | import("io-ts").Type<{
|
|
@@ -13,8 +13,9 @@ const ImportSlices = (staticSlices) => {
|
|
|
13
13
|
const supportedSlices = (0, utils_1.extractSupportedSlices)(staticSlices);
|
|
14
14
|
// For now we only support the SharedSlice, however if we want to support more in the future
|
|
15
15
|
// we would have to change the codec here to something like this: t.array(t.union([ImportSharedSlice(sharedSlices), NewSliceCodec(newSliceCustomTypes)])).
|
|
16
|
-
const
|
|
17
|
-
|
|
16
|
+
const SharedSliceCodec = (0, SharedSlice_1.SharedSlice)(supportedSlices);
|
|
17
|
+
const SlicesArrayCodec = t.array(SharedSliceCodec);
|
|
18
|
+
return (0, ImportContent_1.ImportContent)("Slices", (0, validators_1.EmptyArrayOrElse)(new t.ArrayType(SlicesArrayCodec.name, (u) => SlicesArrayCodec.is(u), (u, c) => {
|
|
18
19
|
return (0, function_1.pipe)(SlicesArrayCodec.validate(u, c), E.chain((slices) => {
|
|
19
20
|
// This part might not make sense for all Slice types in the future, but for now we only support the SharedSlice
|
|
20
21
|
// In case we support more in the future, we would have to filter only the relevant type for this check
|
|
@@ -24,6 +25,6 @@ const ImportSlices = (staticSlices) => {
|
|
|
24
25
|
}
|
|
25
26
|
return t.success(slices);
|
|
26
27
|
}));
|
|
27
|
-
}, t.identity)));
|
|
28
|
+
}, t.identity, SharedSliceCodec)));
|
|
28
29
|
};
|
|
29
30
|
exports.ImportSlices = ImportSlices;
|
|
@@ -58,8 +58,8 @@ const SharedSliceContentEntry = (sliceName, sliceContentField, sliceFieldModels)
|
|
|
58
58
|
]), E.mapLeft((errors) => errors.map((error) => {
|
|
59
59
|
const context = [
|
|
60
60
|
...c,
|
|
61
|
-
...error.context.filter(({ key }) => !!key),
|
|
62
61
|
{ key, actual: content, type: codec },
|
|
62
|
+
...error.context.slice(1), // We ignore the first context element with "" key coming from ImportNestable decoder
|
|
63
63
|
];
|
|
64
64
|
const updatedError = { ...error, context };
|
|
65
65
|
return updatedError;
|
|
@@ -20,5 +20,5 @@ export declare const ImportRichText: (customType?: ({
|
|
|
20
20
|
}) | undefined) => t.Type<{
|
|
21
21
|
type: "StructuredText";
|
|
22
22
|
value: ImportBlock[] | null;
|
|
23
|
-
},
|
|
23
|
+
}, ImportBlock[] | undefined, unknown>;
|
|
24
24
|
export declare type ImportRichText = t.TypeOf<ReturnType<typeof ImportRichText>>;
|
|
@@ -2,25 +2,31 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ImportRichText = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const E = (0, tslib_1.__importStar)(require("fp-ts/Either"));
|
|
6
|
+
const function_1 = require("fp-ts/function");
|
|
5
7
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
8
|
const validators_1 = require("../../../../../validators");
|
|
7
|
-
const
|
|
9
|
+
const function_2 = require("../../../../../validators/function");
|
|
8
10
|
const ImportContent_1 = require("../../ImportContent");
|
|
9
11
|
const ImportBlock_1 = require("./ImportBlock");
|
|
10
|
-
const ImportRichText = (customType) =>
|
|
12
|
+
const ImportRichText = (customType) => {
|
|
11
13
|
var _a, _b, _c, _d;
|
|
12
14
|
const single = (_b = (_a = customType === null || customType === void 0 ? void 0 : customType.config) === null || _a === void 0 ? void 0 : _a.single) === null || _b === void 0 ? void 0 : _b.split(",");
|
|
13
15
|
const multi = (_d = (_c = customType === null || customType === void 0 ? void 0 : customType.config) === null || _c === void 0 ? void 0 : _c.multi) === null || _d === void 0 ? void 0 : _d.split(",");
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
16
|
+
const allowedBlockTypes = multi || single;
|
|
17
|
+
const isSingleBlockAllowed = multi === undefined && single !== undefined;
|
|
18
|
+
const BlockCodec = (0, ImportBlock_1.ImportBlock)(allowedBlockTypes !== null && allowedBlockTypes !== void 0 ? allowedBlockTypes : []);
|
|
19
|
+
const RichTextArrayCodec = (0, function_2.withCustomError)(t.array(BlockCodec), () => "Rich text field must be an array");
|
|
20
|
+
return (0, ImportContent_1.ImportContent)("StructuredText", (0, validators_1.EmptyArrayOrElse)(new t.ArrayType(RichTextArrayCodec.name, (u) => RichTextArrayCodec.is(u), (u, c) => {
|
|
21
|
+
if (allowedBlockTypes === undefined) {
|
|
22
|
+
throw new Error("Invalid custom type for the rich text field: the model is missing a 'single' or 'multi' field defining a list of allowed block types");
|
|
23
|
+
}
|
|
24
|
+
return (0, function_1.pipe)(RichTextArrayCodec.validate(u, c), E.chain((blocks) => {
|
|
25
|
+
if (isSingleBlockAllowed && blocks.length > 1) {
|
|
26
|
+
return t.failure(blocks, c, "This field only allows one block");
|
|
27
|
+
}
|
|
28
|
+
return t.success(blocks);
|
|
29
|
+
}));
|
|
30
|
+
}, t.identity, BlockCodec)));
|
|
31
|
+
};
|
|
26
32
|
exports.ImportRichText = ImportRichText;
|
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
2
|
export declare const ImportImageBlockType: t.LiteralC<"image">;
|
|
3
3
|
export declare type ImportImageBlockType = t.TypeOf<typeof ImportImageBlockType>;
|
|
4
|
-
export declare const ImportImageBlock: t.ExactC<t.TypeC<{
|
|
4
|
+
export declare const ImportImageBlock: t.ExactC<t.IntersectionC<[t.TypeC<{
|
|
5
5
|
type: t.LiteralC<"image">;
|
|
6
|
+
}>, t.IntersectionC<[t.TypeC<{
|
|
6
7
|
id: t.StringC;
|
|
7
|
-
}
|
|
8
|
+
}>, t.PartialC<{
|
|
9
|
+
dimensions: t.PartialC<{
|
|
10
|
+
width: t.NumberC;
|
|
11
|
+
height: t.NumberC;
|
|
12
|
+
}>;
|
|
13
|
+
edit: t.PartialC<{
|
|
14
|
+
x: t.NumberC;
|
|
15
|
+
y: t.NumberC;
|
|
16
|
+
zoom: t.NumberC;
|
|
17
|
+
background: t.StringC;
|
|
18
|
+
}>;
|
|
19
|
+
copyright: t.UnionC<[t.StringC, t.NullC]>;
|
|
20
|
+
alt: t.UnionC<[t.StringC, t.NullC]>;
|
|
21
|
+
}>]>]>>;
|
|
8
22
|
export declare type ImportImageBlock = t.TypeOf<typeof ImportImageBlock>;
|
|
@@ -3,9 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.ImportImageBlock = exports.ImportImageBlockType = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
|
-
const validators_1 = require("
|
|
6
|
+
const validators_1 = require("../../Image/validators");
|
|
7
7
|
exports.ImportImageBlockType = t.literal("image");
|
|
8
|
-
exports.ImportImageBlock = t.
|
|
9
|
-
type
|
|
10
|
-
|
|
11
|
-
})
|
|
8
|
+
exports.ImportImageBlock = t.exact(t.intersection([
|
|
9
|
+
t.type({
|
|
10
|
+
type: exports.ImportImageBlockType,
|
|
11
|
+
}),
|
|
12
|
+
validators_1.ImportImageView,
|
|
13
|
+
]));
|
|
@@ -62,7 +62,7 @@ export declare const ImportNestable: {
|
|
|
62
62
|
} | undefined, unknown> | import("io-ts").Type<{
|
|
63
63
|
type: "StructuredText";
|
|
64
64
|
value: import("./ImportRichText").ImportBlock[] | null;
|
|
65
|
-
},
|
|
65
|
+
}, import("./ImportRichText").ImportBlock[] | undefined, unknown> | import("io-ts").Type<{
|
|
66
66
|
type: "Number";
|
|
67
67
|
value: number | null;
|
|
68
68
|
}, number | undefined, unknown> | import("io-ts").Type<{
|
|
@@ -6,10 +6,10 @@ const Either_1 = require("fp-ts/lib/Either");
|
|
|
6
6
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
7
7
|
const BasicTypes_1 = require("./BasicTypes");
|
|
8
8
|
const DefaultOrElse = (inputValidator) => {
|
|
9
|
-
return (codec) => new t.Type(
|
|
10
|
-
if ((0, Either_1.isRight)(inputValidator.
|
|
9
|
+
return (codec) => new t.Type(`DefaultOrElse<${inputValidator.name}, ${codec.name}>`, (u) => null === u || codec.is(u), (u, c) => {
|
|
10
|
+
if ((0, Either_1.isRight)(inputValidator.validate(u, c)))
|
|
11
11
|
return t.success(null);
|
|
12
|
-
return codec.
|
|
12
|
+
return codec.validate(u, c);
|
|
13
13
|
}, (chunk) => (chunk ? codec.encode(chunk) : undefined));
|
|
14
14
|
};
|
|
15
15
|
exports.DefaultOrElse = DefaultOrElse;
|
package/package.json
CHANGED
package/src/_internal/utils.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type {
|
|
|
4
4
|
WidgetContent,
|
|
5
5
|
} from "../content"
|
|
6
6
|
import type {
|
|
7
|
-
|
|
7
|
+
CompositeSlice,
|
|
8
8
|
Group,
|
|
9
9
|
NestableWidget,
|
|
10
10
|
StaticSlices,
|
|
@@ -18,7 +18,7 @@ export type PickOnly<T, K extends keyof T> = Pick<T, K> & {
|
|
|
18
18
|
|
|
19
19
|
export type TraverseSliceContentFn = <
|
|
20
20
|
S extends SliceItemContent | SharedSliceItemContent,
|
|
21
|
-
D extends VariationFields |
|
|
21
|
+
D extends VariationFields | CompositeSlice | Group | NestableWidget,
|
|
22
22
|
>({
|
|
23
23
|
path,
|
|
24
24
|
key,
|
|
@@ -91,5 +91,5 @@ export const ContentPath = {
|
|
|
91
91
|
export type SliceModel =
|
|
92
92
|
| VariationFields
|
|
93
93
|
| NestableWidget
|
|
94
|
-
|
|
|
94
|
+
| CompositeSlice
|
|
95
95
|
| Group
|