@prismicio/types-internal 2.2.0-alpha.16 → 2.2.0-alpha.18
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/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/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/converters/fields/utils.d.ts +0 -1
- package/lib/import/converters/fields/utils.js +0 -10
- package/lib/import/validators/fields/nestable/Image/Decoder.d.ts +0 -26
- package/lib/validators/NullOrT.d.ts +0 -2
- package/lib/validators/NullOrT.js +0 -13
|
@@ -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
|
} & {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ImportImage = void 0;
|
|
3
|
+
exports.ImportImage = exports.ImageFieldCodec = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const Either_1 = require("fp-ts/Either");
|
|
6
6
|
const function_1 = require("fp-ts/function");
|
|
@@ -8,34 +8,34 @@ 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 ImportContent_1 = require("../../ImportContent");
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
...acc,
|
|
21
|
-
[thumbnail.name]: validators_1.EmptyObject,
|
|
22
|
-
}), {})), () => "The value must be an object");
|
|
23
|
-
};
|
|
24
|
-
const ImageField = (field) => new t.Type("ImageField", (u) => Validator_1.ImageFieldValidator.is(u) &&
|
|
11
|
+
const default_1 = require("./default");
|
|
12
|
+
const merge_1 = require("./merge");
|
|
13
|
+
const validators_2 = require("./validators");
|
|
14
|
+
/* For code clarity, the output of this validator will be simplified
|
|
15
|
+
*
|
|
16
|
+
* Input -> type ImageAPIV2 = ImportImageView & ImportThumbnails
|
|
17
|
+
* Output -> type ImageWithThumbnails 👇
|
|
18
|
+
*/
|
|
19
|
+
const ImageFieldCodec = (field) => new t.Type("ImageField", (u) => validators_2.ImportImageView.is(u) &&
|
|
25
20
|
"thumbnails" in u &&
|
|
26
|
-
|
|
27
|
-
return (0, function_1.pipe)(
|
|
28
|
-
|
|
29
|
-
|
|
21
|
+
validators_2.ImportThumbnails.is(u["thumbnails"]), (u, ctx) => {
|
|
22
|
+
return (0, function_1.pipe)(
|
|
23
|
+
// Validating the higher level image
|
|
24
|
+
validators_2.ImportImageView.validate(u, ctx), (0, Either_1.chain)((imageApiV2) => {
|
|
25
|
+
const { id, dimensions, edit, copyright, alt, ...thumbnails } = imageApiV2;
|
|
26
|
+
return (0, function_1.pipe)(
|
|
27
|
+
// Validating the thumbnails
|
|
28
|
+
validators_2.ImportThumbnails.validate(thumbnails, ctx), (0, Either_1.map)((thumbnails) => {
|
|
30
29
|
var _a;
|
|
31
30
|
return ({
|
|
32
|
-
...(0,
|
|
33
|
-
thumbnails: (0,
|
|
31
|
+
...(0, merge_1.mergeImageViewWithCtConstraints)(imageApiV2, imageApiV2, (_a = field === null || field === void 0 ? void 0 : field.config) === null || _a === void 0 ? void 0 : _a.constraint),
|
|
32
|
+
thumbnails: (0, merge_1.mergeThumbnailsWithCtConstraints)(thumbnails, imageApiV2, field),
|
|
34
33
|
});
|
|
35
34
|
}));
|
|
36
35
|
}));
|
|
37
36
|
}, t.identity);
|
|
38
|
-
|
|
37
|
+
exports.ImageFieldCodec = ImageFieldCodec;
|
|
38
|
+
const ImageCodec = (field) => (0, function_2.withCustomError)((0, validators_1.DefaultOrElse)((0, default_1.defaultImportImage)(field))((0, exports.ImageFieldCodec)(field)), () => "An image field must be an object");
|
|
39
39
|
const ImportImage = (field) => (0, ImportContent_1.ImportContent)("Image", ImageCodec(field));
|
|
40
40
|
exports.ImportImage = ImportImage;
|
|
41
41
|
(0, tslib_1.__exportStar)(require("./model"), exports);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type ImageConstraint from "../../../../../customtypes/widgets/shared/ImageConstraint";
|
|
2
|
+
import type { ImageField } from "./model";
|
|
3
|
+
import type { ImportImageView, ImportThumbnails } from "./validators";
|
|
4
|
+
export declare const mergeImageViewWithCtConstraints: (image: ImportImageView | undefined, defaultImage: ImportImageView, constraints: ImageConstraint | undefined) => ImageField;
|
|
5
|
+
export declare const mergeThumbnailsWithCtConstraints: (thumbnails: ImportThumbnails, defaultImage: ImportImageView, field?: ({
|
|
6
|
+
type: "Image";
|
|
7
|
+
} & {
|
|
8
|
+
fieldset?: string | null | undefined;
|
|
9
|
+
config?: {
|
|
10
|
+
label?: string | null | undefined;
|
|
11
|
+
placeholder?: string;
|
|
12
|
+
constraint?: {
|
|
13
|
+
width?: number | null;
|
|
14
|
+
height?: number | null;
|
|
15
|
+
};
|
|
16
|
+
thumbnails?: readonly ({
|
|
17
|
+
name: string;
|
|
18
|
+
} & {
|
|
19
|
+
width?: number | null;
|
|
20
|
+
height?: number | null;
|
|
21
|
+
})[];
|
|
22
|
+
};
|
|
23
|
+
}) | undefined) => {};
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
3
|
+
exports.mergeThumbnailsWithCtConstraints = exports.mergeImageViewWithCtConstraints = void 0;
|
|
4
|
+
/* This function merges user input with custom type constraints.
|
|
5
|
+
* If a thumbnails' data are missing (`image`) then the default is used (`defaultImage`)
|
|
6
|
+
*/
|
|
7
|
+
const mergeImageViewWithCtConstraints = (image, defaultImage, constraints) => {
|
|
8
8
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
9
9
|
const background = (_a = image === null || image === void 0 ? void 0 : image.edit) === null || _a === void 0 ? void 0 : _a.background;
|
|
10
|
-
const width = (_d = (_b = constraints === null || constraints === void 0 ? void 0 : constraints.width) !== null && _b !== void 0 ? _b : (_c = image === null || image === void 0 ? void 0 : image.dimensions) === null || _c === void 0 ? void 0 : _c.width) !== null && _d !== void 0 ? _d : (_e =
|
|
11
|
-
const height = (_h = (_f = constraints === null || constraints === void 0 ? void 0 : constraints.height) !== null && _f !== void 0 ? _f : (_g = image === null || image === void 0 ? void 0 : image.dimensions) === null || _g === void 0 ? void 0 : _g.height) !== null && _h !== void 0 ? _h : (_j =
|
|
10
|
+
const width = (_d = (_b = constraints === null || constraints === void 0 ? void 0 : constraints.width) !== null && _b !== void 0 ? _b : (_c = image === null || image === void 0 ? void 0 : image.dimensions) === null || _c === void 0 ? void 0 : _c.width) !== null && _d !== void 0 ? _d : (_e = defaultImage === null || defaultImage === void 0 ? void 0 : defaultImage.dimensions) === null || _e === void 0 ? void 0 : _e.width;
|
|
11
|
+
const height = (_h = (_f = constraints === null || constraints === void 0 ? void 0 : constraints.height) !== null && _f !== void 0 ? _f : (_g = image === null || image === void 0 ? void 0 : image.dimensions) === null || _g === void 0 ? void 0 : _g.height) !== null && _h !== void 0 ? _h : (_j = defaultImage === null || defaultImage === void 0 ? void 0 : defaultImage.dimensions) === null || _j === void 0 ? void 0 : _j.height;
|
|
12
12
|
const alt = image === null || image === void 0 ? void 0 : image.alt;
|
|
13
13
|
const copyright = image === null || image === void 0 ? void 0 : image.copyright;
|
|
14
14
|
return {
|
|
15
|
-
id: (_k = image === null || image === void 0 ? void 0 : image.id) !== null && _k !== void 0 ? _k :
|
|
15
|
+
id: (_k = image === null || image === void 0 ? void 0 : image.id) !== null && _k !== void 0 ? _k : defaultImage === null || defaultImage === void 0 ? void 0 : defaultImage.id,
|
|
16
16
|
edit: {
|
|
17
17
|
x: (_m = (_l = image === null || image === void 0 ? void 0 : image.edit) === null || _l === void 0 ? void 0 : _l.x) !== null && _m !== void 0 ? _m : 0,
|
|
18
18
|
y: (_p = (_o = image === null || image === void 0 ? void 0 : image.edit) === null || _o === void 0 ? void 0 : _o.y) !== null && _p !== void 0 ? _p : 0,
|
|
@@ -27,14 +27,18 @@ const decodeImageField = (image, mainImage, constraints) => {
|
|
|
27
27
|
...(copyright !== undefined ? { copyright } : {}),
|
|
28
28
|
};
|
|
29
29
|
};
|
|
30
|
-
exports.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
exports.mergeImageViewWithCtConstraints = mergeImageViewWithCtConstraints;
|
|
31
|
+
/* This function handles each thumbnail defined in the custom type.
|
|
32
|
+
*
|
|
33
|
+
* For each of them it merges the user input with custom type constraints.
|
|
34
|
+
*
|
|
35
|
+
* If a thumbnail is missing, the data from the default image is used.
|
|
36
|
+
*/
|
|
37
|
+
const mergeThumbnailsWithCtConstraints = (thumbnails, defaultImage, field) => {
|
|
34
38
|
var _a, _b, _c;
|
|
35
39
|
return (_c = (_b = (_a = field === null || field === void 0 ? void 0 : field.config) === null || _a === void 0 ? void 0 : _a.thumbnails) === null || _b === void 0 ? void 0 : _b.reduce((acc, thumbnail) => ({
|
|
36
40
|
...acc,
|
|
37
|
-
[thumbnail.name]: (0, exports.
|
|
41
|
+
[thumbnail.name]: (0, exports.mergeImageViewWithCtConstraints)(thumbnails[thumbnail.name], defaultImage, thumbnail),
|
|
38
42
|
}), {})) !== null && _c !== void 0 ? _c : {};
|
|
39
43
|
};
|
|
40
|
-
exports.
|
|
44
|
+
exports.mergeThumbnailsWithCtConstraints = mergeThumbnailsWithCtConstraints;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as t from "io-ts";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const ImportImageView: t.IntersectionC<[t.TypeC<{
|
|
3
3
|
id: t.StringC;
|
|
4
4
|
}>, t.PartialC<{
|
|
5
5
|
dimensions: t.PartialC<{
|
|
@@ -15,7 +15,8 @@ export declare const ImageFieldValidator: t.IntersectionC<[t.TypeC<{
|
|
|
15
15
|
copyright: t.UnionC<[t.StringC, t.NullC]>;
|
|
16
16
|
alt: t.UnionC<[t.StringC, t.NullC]>;
|
|
17
17
|
}>]>;
|
|
18
|
-
export declare
|
|
18
|
+
export declare type ImportImageView = t.TypeOf<typeof ImportImageView>;
|
|
19
|
+
export declare const ImportThumbnails: t.RecordC<t.StringC, t.IntersectionC<[t.TypeC<{
|
|
19
20
|
id: t.StringC;
|
|
20
21
|
}>, t.PartialC<{
|
|
21
22
|
dimensions: t.PartialC<{
|
|
@@ -31,3 +32,4 @@ export declare const ThumbnailsValidator: t.RecordC<t.StringC, t.IntersectionC<[
|
|
|
31
32
|
copyright: t.UnionC<[t.StringC, t.NullC]>;
|
|
32
33
|
alt: t.UnionC<[t.StringC, t.NullC]>;
|
|
33
34
|
}>]>>;
|
|
35
|
+
export declare type ImportThumbnails = t.TypeOf<typeof ImportThumbnails>;
|
|
@@ -1,27 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ImportThumbnails = exports.ImportImageView = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
6
|
const BasicTypes_1 = require("../../../../../validators/BasicTypes");
|
|
7
7
|
const function_1 = require("../../../../../validators/function");
|
|
8
|
-
exports.
|
|
8
|
+
exports.ImportImageView = (0, function_1.withCustomError)(t.intersection([
|
|
9
9
|
t.type({
|
|
10
|
+
// Image Id
|
|
10
11
|
id: BasicTypes_1.String,
|
|
11
12
|
}),
|
|
12
13
|
t.partial({
|
|
14
|
+
// Dimensions here will be used if they are not defined in the custom type
|
|
13
15
|
dimensions: (0, function_1.withCustomError)(t.partial({
|
|
14
16
|
width: BasicTypes_1.Number,
|
|
15
17
|
height: BasicTypes_1.Number,
|
|
16
18
|
}), () => "The value must be an object"),
|
|
19
|
+
// Crop information
|
|
17
20
|
edit: (0, function_1.withCustomError)(t.partial({
|
|
18
21
|
x: BasicTypes_1.Number,
|
|
19
22
|
y: BasicTypes_1.Number,
|
|
20
23
|
zoom: BasicTypes_1.Number,
|
|
21
24
|
background: BasicTypes_1.String,
|
|
22
25
|
}), () => "The value must be an object"),
|
|
26
|
+
// Copyrights and alt are set in the Asset by default but they can be overrided
|
|
23
27
|
copyright: BasicTypes_1.StringOrNull,
|
|
24
28
|
alt: BasicTypes_1.StringOrNull,
|
|
25
29
|
}),
|
|
26
30
|
]), () => "The value must be an object");
|
|
27
|
-
exports.
|
|
31
|
+
exports.ImportThumbnails = t.record(t.string, exports.ImportImageView);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as t from "io-ts";
|
|
2
|
+
import { ImportBlockType, ImportEmbedBlock, ImportImageBlock, ImportTextBlock } from "./blocks";
|
|
3
|
+
export declare type ImportBlock = ImportTextBlock | ImportImageBlock | ImportEmbedBlock;
|
|
4
|
+
export declare const ImportBlock: (allowedBlockTypes: string[]) => t.Type<ImportBlock, {
|
|
5
|
+
type: ImportBlockType;
|
|
6
|
+
}, unknown>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImportBlock = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
6
|
+
const function_1 = require("../../../../../validators/function");
|
|
7
|
+
const blocks_1 = require("./blocks");
|
|
8
|
+
const ImportBlock = (allowedBlockTypes) => (0, function_1.withCustomError)(t
|
|
9
|
+
.type({
|
|
10
|
+
type: (0, blocks_1.ImportBlockType)(allowedBlockTypes),
|
|
11
|
+
})
|
|
12
|
+
.pipe(new t.Type("ImportBlock", (u) => t
|
|
13
|
+
.union([blocks_1.ImportTextBlock, blocks_1.ImportImageBlock, blocks_1.ImportEmbedBlock])
|
|
14
|
+
.is(u), (u, c) => {
|
|
15
|
+
if (u.type === "image") {
|
|
16
|
+
return blocks_1.ImportImageBlock.validate(u, c);
|
|
17
|
+
}
|
|
18
|
+
else if (u.type === "embed") {
|
|
19
|
+
return blocks_1.ImportEmbedBlock.validate(u, c);
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
return blocks_1.ImportTextBlock.validate(u, c);
|
|
23
|
+
}
|
|
24
|
+
}, t.identity)), () => "Rich text block must be an object");
|
|
25
|
+
exports.ImportBlock = ImportBlock;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as t from "io-ts";
|
|
2
|
+
import { ImportBlock } from "./ImportBlock";
|
|
3
|
+
export declare const ImportRichText: (customType?: ({
|
|
4
|
+
type: "StructuredText";
|
|
5
|
+
} & {
|
|
6
|
+
fieldset?: string | null | undefined;
|
|
7
|
+
config?: {
|
|
8
|
+
label?: string | null | undefined;
|
|
9
|
+
placeholder?: string;
|
|
10
|
+
useAsTitle?: boolean;
|
|
11
|
+
single?: string;
|
|
12
|
+
multi?: string;
|
|
13
|
+
imageConstraint?: {
|
|
14
|
+
width?: number | null;
|
|
15
|
+
height?: number | null;
|
|
16
|
+
};
|
|
17
|
+
labels?: readonly string[];
|
|
18
|
+
allowTargetBlank?: boolean;
|
|
19
|
+
};
|
|
20
|
+
}) | undefined) => t.Type<{
|
|
21
|
+
type: "StructuredText";
|
|
22
|
+
value: ImportBlock[] | null;
|
|
23
|
+
}, unknown[] | undefined, unknown>;
|
|
24
|
+
export declare type ImportRichText = t.TypeOf<ReturnType<typeof ImportRichText>>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImportRichText = 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 ImportContent_1 = require("../../ImportContent");
|
|
9
|
+
const ImportBlock_1 = require("./ImportBlock");
|
|
10
|
+
const ImportRichText = (customType) => (0, ImportContent_1.ImportContent)("StructuredText", (0, validators_1.EmptyArrayOrElse)((0, function_1.withCustomError)(t.array(t.unknown).pipe(new t.Type("RichTextField", (u) => t.array((0, ImportBlock_1.ImportBlock)([])).is(u), (u, c) => {
|
|
11
|
+
var _a, _b, _c, _d;
|
|
12
|
+
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
|
+
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
|
+
if (multi) {
|
|
15
|
+
return t.array((0, ImportBlock_1.ImportBlock)(multi)).validate(u, c);
|
|
16
|
+
}
|
|
17
|
+
else if (single) {
|
|
18
|
+
return u.length > 1
|
|
19
|
+
? t.failure(u, c, "This field only allows one block")
|
|
20
|
+
: t.array((0, ImportBlock_1.ImportBlock)(single)).validate(u, c);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
throw new Error("Rich text config must have either a 'single' or 'multi' field defined");
|
|
24
|
+
}
|
|
25
|
+
}, t.identity)), () => "Rich text field must be an array")));
|
|
26
|
+
exports.ImportRichText = ImportRichText;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as t from "io-ts";
|
|
2
|
+
import { ImportEmbedBlockType } from "./ImportEmbedBlock";
|
|
3
|
+
import { ImportImageBlockType } from "./ImportImageBlock";
|
|
4
|
+
import { ImportTextBlockType } from "./ImportTextBlock";
|
|
5
|
+
export declare type ImportBlockType = ImportTextBlockType | ImportImageBlockType | ImportEmbedBlockType;
|
|
6
|
+
export declare const ImportBlockType: (allowedBlockTypes: string[]) => t.Type<ImportBlockType, ImportBlockType, unknown>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ImportBlockType = void 0;
|
|
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");
|
|
7
|
+
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
8
|
+
const function_2 = require("../../../../../../validators/function");
|
|
9
|
+
const ImportEmbedBlock_1 = require("./ImportEmbedBlock");
|
|
10
|
+
const ImportImageBlock_1 = require("./ImportImageBlock");
|
|
11
|
+
const ImportTextBlock_1 = require("./ImportTextBlock");
|
|
12
|
+
const ImportBlockTypeValidator = (0, function_2.withCustomError)(t.union([ImportTextBlock_1.ImportTextBlockType, ImportImageBlock_1.ImportImageBlockType, ImportEmbedBlock_1.ImportEmbedBlockType]), () => `Invalid block type. Supported block types are: ${Object.keys(ImportTextBlock_1.ImportTextBlockType.keys).join(", ")}, ${ImportImageBlock_1.ImportImageBlockType.value}, ${ImportEmbedBlock_1.ImportEmbedBlockType.value}`);
|
|
13
|
+
const ImportBlockType = (allowedBlockTypes) => new t.Type("ImportBlockType", (u) => ImportBlockTypeValidator.is(u), (u, c) => {
|
|
14
|
+
return (0, function_1.pipe)(ImportBlockTypeValidator.validate(u, c), E.chain((validBlockType) => allowedBlockTypes.includes(validBlockType)
|
|
15
|
+
? t.success(validBlockType)
|
|
16
|
+
: t.failure(u, c, `The block type '${validBlockType}' is not allowed in your document type. Enable the type for this rich text field to create the document.`)));
|
|
17
|
+
}, t.identity);
|
|
18
|
+
exports.ImportBlockType = ImportBlockType;
|