@prismicio/types-internal 2.2.0-alpha.9 → 2.2.0-traverse.alpha-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_internal/utils.d.ts +17 -0
- package/lib/_internal/utils.js +9 -0
- package/lib/common/Asset.d.ts +3 -4
- package/lib/common/Embed.d.ts +1 -2
- package/lib/common/UUID.d.ts +7 -0
- package/lib/common/UUID.js +8 -0
- package/lib/common/index.d.ts +1 -0
- package/lib/common/index.js +1 -0
- package/lib/content/Document.d.ts +22 -3
- package/lib/content/Document.js +71 -1
- package/lib/content/fields/GroupContent.d.ts +7 -0
- package/lib/content/fields/GroupContent.js +34 -1
- package/lib/content/fields/WidgetContent.d.ts +6 -6
- package/lib/content/fields/nestable/NestableContent.d.ts +2 -0
- package/lib/content/fields/nestable/NestableContent.js +29 -1
- package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +8 -0
- package/lib/content/fields/slices/Slice/CompositeSliceContent.js +56 -1
- package/lib/content/fields/slices/Slice/RepeatableContent.js +0 -1
- package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +8 -0
- package/lib/content/fields/slices/Slice/SharedSliceContent.js +58 -1
- package/lib/content/fields/slices/SlicesContent.d.ts +7 -0
- package/lib/content/fields/slices/SlicesContent.js +70 -1
- package/lib/customtypes/CustomType.d.ts +1 -0
- package/lib/customtypes/CustomType.js +8 -1
- package/lib/customtypes/widgets/slices/CompositeSlice.d.ts +2 -0
- package/lib/customtypes/widgets/slices/CompositeSlice.js +5 -1
- package/lib/customtypes/widgets/slices/LegacySlice.d.ts +2 -0
- package/lib/customtypes/widgets/slices/LegacySlice.js +5 -1
- package/lib/customtypes/widgets/slices/SharedSlice.d.ts +4 -0
- package/lib/customtypes/widgets/slices/SharedSlice.js +9 -1
- package/lib/import/converters/Document.d.ts +2 -2
- package/lib/import/converters/Document.js +6 -6
- package/lib/import/converters/fields/Slices/SharedSlice.d.ts +4 -0
- package/lib/import/converters/fields/Slices/SharedSlice.js +19 -0
- package/lib/import/converters/fields/Slices/SharedSliceContent.d.ts +10 -0
- package/lib/import/converters/fields/Slices/SharedSliceContent.js +58 -0
- package/lib/import/converters/fields/Slices/Slices.d.ts +4 -0
- package/lib/import/converters/fields/Slices/Slices.js +16 -0
- package/lib/import/converters/fields/Slices/index.d.ts +1 -0
- package/lib/import/converters/fields/Slices/index.js +4 -0
- package/lib/import/converters/fields/UID.d.ts +1 -1
- package/lib/import/converters/fields/UID.js +0 -2
- package/lib/import/converters/fields/index.d.ts +1 -0
- package/lib/import/converters/fields/index.js +1 -0
- package/lib/import/converters/fields/nestable/Embed.d.ts +2 -1
- package/lib/import/converters/fields/nestable/Embed.js +24 -5
- package/lib/import/converters/fields/nestable/Image.d.ts +2 -2
- package/lib/import/converters/fields/nestable/Image.js +1 -1
- package/lib/import/converters/fields/nestable/Link.d.ts +1 -1
- package/lib/import/converters/fields/nestable/Link.js +6 -6
- package/lib/import/converters/fields/nestable/Nestable.d.ts +4 -3
- package/lib/import/converters/fields/nestable/Nestable.js +2 -2
- package/lib/import/validators/Document.js +2 -2
- package/lib/import/validators/fields/ImportField.d.ts +17 -68
- package/lib/import/validators/fields/ImportField.js +8 -4
- package/lib/import/validators/fields/ImportSlices/ImportSlices.d.ts +8 -0
- package/lib/import/validators/fields/ImportSlices/ImportSlices.js +29 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.d.ts +14 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.js +61 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/errors.d.ts +4 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/errors.js +7 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.d.ts +2 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.js +15 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.d.ts +17 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.js +30 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.d.ts +43 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.js +69 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/errors.d.ts +4 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/errors.js +6 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/index.d.ts +2 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/index.js +5 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/types.d.ts +1 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/types.js +2 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.d.ts +9 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.js +39 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.d.ts +11 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.js +24 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.d.ts +11 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.js +24 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/index.d.ts +5 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/fields/index.js +8 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/index.d.ts +3 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/index.js +6 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/utils.d.ts +339 -0
- package/lib/import/validators/fields/ImportSlices/SharedSlice/utils.js +11 -0
- package/lib/import/validators/fields/ImportSlices/index.d.ts +1 -0
- package/lib/import/validators/fields/ImportSlices/index.js +4 -0
- package/lib/import/validators/fields/ImportSlices/utils.d.ts +4 -0
- package/lib/import/validators/fields/ImportSlices/utils.js +35 -0
- package/lib/import/validators/fields/UID.d.ts +2 -2
- package/lib/import/validators/fields/UID.js +1 -1
- package/lib/import/validators/fields/nestable/Embed.d.ts +6 -23
- package/lib/import/validators/fields/nestable/Embed.js +7 -25
- package/lib/import/validators/fields/nestable/GeoPoint.js +1 -1
- package/lib/import/validators/fields/nestable/Image/Decoder.d.ts +26 -0
- package/lib/import/validators/fields/nestable/Image/Decoder.js +40 -0
- package/lib/import/validators/fields/nestable/Image/Validator.d.ts +33 -0
- package/lib/import/validators/fields/nestable/Image/Validator.js +27 -0
- package/lib/import/validators/fields/nestable/Image/index.d.ts +26 -0
- package/lib/import/validators/fields/nestable/Image/index.js +41 -0
- package/lib/import/validators/fields/nestable/Image/model.d.ts +18 -0
- package/lib/import/validators/fields/nestable/Image/model.js +2 -0
- package/lib/import/validators/fields/nestable/Link.js +2 -2
- package/lib/import/validators/fields/nestable/Nestable.d.ts +9 -60
- package/lib/import/validators/fields/nestable/index.d.ts +1 -0
- package/lib/import/validators/fields/nestable/index.js +1 -0
- package/lib/utils/DocumentId.d.ts +2 -1
- package/lib/utils/DocumentId.js +3 -3
- package/lib/utils/io-ts.d.ts +2 -0
- package/lib/utils/io-ts.js +22 -0
- package/lib/validators/BasicTypes.d.ts +0 -1
- package/lib/validators/BasicTypes.js +7 -8
- package/lib/validators/DefaultOrElse.js +1 -1
- package/lib/validators/NonEmptyString.js +1 -1
- package/lib/validators/NullOrT.d.ts +2 -0
- package/lib/validators/NullOrT.js +12 -0
- package/lib/validators/function.d.ts +4 -4
- package/lib/validators/function.js +6 -6
- package/package.json +4 -2
- package/src/_internal/utils.ts +39 -0
- package/src/common/Asset.ts +4 -5
- package/src/common/Embed.ts +22 -0
- package/src/common/UUID.ts +19 -0
- package/src/common/index.ts +1 -0
- package/src/content/Document.ts +96 -1
- package/src/content/fields/GroupContent.ts +47 -0
- package/src/content/fields/nestable/NestableContent.ts +32 -0
- package/src/content/fields/slices/Slice/CompositeSliceContent.ts +77 -0
- package/src/content/fields/slices/Slice/RepeatableContent.ts +0 -1
- package/src/content/fields/slices/Slice/SharedSliceContent.ts +82 -0
- package/src/content/fields/slices/SlicesContent.ts +96 -0
- package/src/customtypes/CustomType.ts +17 -0
- package/src/customtypes/widgets/slices/CompositeSlice.ts +7 -0
- package/src/customtypes/widgets/slices/LegacySlice.ts +7 -0
- package/src/customtypes/widgets/slices/SharedSlice.ts +12 -0
- package/src/import/converters/Document.ts +10 -8
- package/src/import/converters/fields/Slices/SharedSlice.ts +24 -0
- package/src/import/converters/fields/Slices/SharedSliceContent.ts +94 -0
- package/src/import/converters/fields/Slices/Slices.ts +20 -0
- package/src/import/converters/fields/Slices/index.ts +1 -0
- package/src/import/converters/fields/UID.ts +1 -5
- package/src/import/converters/fields/index.ts +1 -0
- package/src/import/converters/fields/nestable/Embed.ts +29 -7
- package/src/import/converters/fields/nestable/Image.ts +4 -4
- package/src/import/converters/fields/nestable/Link.ts +5 -5
- package/src/import/converters/fields/nestable/Nestable.ts +7 -5
- package/src/import/validators/Document.ts +3 -3
- package/src/import/validators/fields/ImportField.ts +12 -6
- package/src/import/validators/fields/ImportSlices/ImportSlices.ts +54 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/SharedSlice.ts +116 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/errors.ts +6 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/OptionalSharedSliceId.ts +20 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContent.ts +64 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/SharedSliceContentEntry.ts +100 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/errors.ts +10 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/index.ts +2 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceContent/types.ts +1 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceId.ts +65 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceType.ts +45 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/SharedSliceVariation.ts +45 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/fields/index.ts +5 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/index.ts +3 -0
- package/src/import/validators/fields/ImportSlices/SharedSlice/utils.ts +21 -0
- package/src/import/validators/fields/ImportSlices/index.ts +1 -0
- package/src/import/validators/fields/ImportSlices/utils.ts +43 -0
- package/src/import/validators/fields/UID.ts +2 -2
- package/src/import/validators/fields/nestable/Embed.ts +9 -41
- package/src/import/validators/fields/nestable/GeoPoint.ts +2 -2
- package/src/import/validators/fields/nestable/Image/Decoder.ts +61 -0
- package/src/import/validators/fields/nestable/Image/Validator.ts +38 -0
- package/src/import/validators/fields/nestable/Image/index.ts +75 -0
- package/src/import/validators/fields/nestable/Image/model.ts +18 -0
- package/src/import/validators/fields/nestable/Link.ts +2 -2
- package/src/import/validators/fields/nestable/index.ts +1 -0
- package/src/utils/DocumentId.ts +4 -5
- package/src/utils/io-ts.ts +29 -0
- package/src/validators/BasicTypes.ts +13 -11
- package/src/validators/DefaultOrElse.ts +1 -1
- package/src/validators/NonEmptyString.ts +4 -5
- package/src/validators/function.ts +4 -4
- package/lib/import/validators/fields/nestable/Image.d.ts +0 -62
- package/lib/import/validators/fields/nestable/Image.js +0 -76
- package/src/import/validators/fields/nestable/Image.ts +0 -147
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import * as t from "io-ts";
|
|
2
|
-
export declare type ImageField = {
|
|
3
|
-
id: string;
|
|
4
|
-
edit: {
|
|
5
|
-
x: number;
|
|
6
|
-
y: number;
|
|
7
|
-
zoom: number;
|
|
8
|
-
background?: string;
|
|
9
|
-
};
|
|
10
|
-
dimensions: {
|
|
11
|
-
width?: number;
|
|
12
|
-
height?: number;
|
|
13
|
-
};
|
|
14
|
-
credit?: string | null;
|
|
15
|
-
alt?: string | null;
|
|
16
|
-
};
|
|
17
|
-
declare type ImageFieldWithThumbnails = ImageField & {
|
|
18
|
-
thumbnails: Record<string, ImageField>;
|
|
19
|
-
};
|
|
20
|
-
declare const ImageFieldWithThumbnails: (field?: ({
|
|
21
|
-
type: "Image";
|
|
22
|
-
} & {
|
|
23
|
-
fieldset?: string | null | undefined;
|
|
24
|
-
config?: {
|
|
25
|
-
label?: string | null | undefined;
|
|
26
|
-
placeholder?: string;
|
|
27
|
-
constraint?: {
|
|
28
|
-
width?: number | null;
|
|
29
|
-
height?: number | null;
|
|
30
|
-
};
|
|
31
|
-
thumbnails?: readonly ({
|
|
32
|
-
name: string;
|
|
33
|
-
} & {
|
|
34
|
-
width?: number | null;
|
|
35
|
-
height?: number | null;
|
|
36
|
-
})[];
|
|
37
|
-
};
|
|
38
|
-
}) | undefined) => t.Type<ImageFieldWithThumbnails, ImageFieldWithThumbnails, unknown>;
|
|
39
|
-
export declare const ImportImage: (field?: ({
|
|
40
|
-
type: "Image";
|
|
41
|
-
} & {
|
|
42
|
-
fieldset?: string | null | undefined;
|
|
43
|
-
config?: {
|
|
44
|
-
label?: string | null | undefined;
|
|
45
|
-
placeholder?: string;
|
|
46
|
-
constraint?: {
|
|
47
|
-
width?: number | null;
|
|
48
|
-
height?: number | null;
|
|
49
|
-
};
|
|
50
|
-
thumbnails?: readonly ({
|
|
51
|
-
name: string;
|
|
52
|
-
} & {
|
|
53
|
-
width?: number | null;
|
|
54
|
-
height?: number | null;
|
|
55
|
-
})[];
|
|
56
|
-
};
|
|
57
|
-
}) | undefined) => t.Type<{
|
|
58
|
-
type: "Image";
|
|
59
|
-
value: ImageFieldWithThumbnails | null;
|
|
60
|
-
}, ImageFieldWithThumbnails | undefined, unknown>;
|
|
61
|
-
export declare type ImportImage = t.TypeOf<ReturnType<typeof ImportImage>>;
|
|
62
|
-
export {};
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ImportImage = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const Either_1 = require("fp-ts/Either");
|
|
6
|
-
const function_1 = require("fp-ts/lib/function");
|
|
7
|
-
const t = (0, tslib_1.__importStar)(require("io-ts"));
|
|
8
|
-
const validators_1 = require("../../../../validators");
|
|
9
|
-
const BasicTypes_1 = require("../../../../validators/BasicTypes");
|
|
10
|
-
const ImportContent_1 = require("../ImportContent");
|
|
11
|
-
const ImageFieldValidator = BasicTypes_1.AnyObject.pipe(t.intersection([
|
|
12
|
-
t.type({
|
|
13
|
-
id: BasicTypes_1.String,
|
|
14
|
-
}),
|
|
15
|
-
t.partial({
|
|
16
|
-
dimensions: BasicTypes_1.AnyObject.pipe(t.partial({
|
|
17
|
-
width: BasicTypes_1.Number,
|
|
18
|
-
height: BasicTypes_1.Number,
|
|
19
|
-
})),
|
|
20
|
-
edit: BasicTypes_1.AnyObject.pipe(t.partial({
|
|
21
|
-
x: BasicTypes_1.Number,
|
|
22
|
-
y: BasicTypes_1.Number,
|
|
23
|
-
zoom: BasicTypes_1.Number,
|
|
24
|
-
background: BasicTypes_1.String,
|
|
25
|
-
})),
|
|
26
|
-
credit: BasicTypes_1.StringOrNull,
|
|
27
|
-
alt: BasicTypes_1.StringOrNull,
|
|
28
|
-
}),
|
|
29
|
-
]));
|
|
30
|
-
const ThumbnailsValidator = t.record(t.string, ImageFieldValidator);
|
|
31
|
-
const encodeImageField = (image, mainImage, constraints) => {
|
|
32
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
33
|
-
const background = (_a = image === null || image === void 0 ? void 0 : image.edit) === null || _a === void 0 ? void 0 : _a.background;
|
|
34
|
-
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 = mainImage.dimensions) === null || _e === void 0 ? void 0 : _e.width;
|
|
35
|
-
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 = mainImage.dimensions) === null || _j === void 0 ? void 0 : _j.height;
|
|
36
|
-
const alt = image === null || image === void 0 ? void 0 : image.alt;
|
|
37
|
-
const credit = image === null || image === void 0 ? void 0 : image.credit;
|
|
38
|
-
return {
|
|
39
|
-
id: (_k = image === null || image === void 0 ? void 0 : image.id) !== null && _k !== void 0 ? _k : mainImage === null || mainImage === void 0 ? void 0 : mainImage.id,
|
|
40
|
-
edit: {
|
|
41
|
-
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,
|
|
42
|
-
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,
|
|
43
|
-
zoom: (_r = (_q = image === null || image === void 0 ? void 0 : image.edit) === null || _q === void 0 ? void 0 : _q.zoom) !== null && _r !== void 0 ? _r : 1,
|
|
44
|
-
...(background !== undefined ? { background } : {}),
|
|
45
|
-
},
|
|
46
|
-
dimensions: {
|
|
47
|
-
...(width !== undefined ? { width } : {}),
|
|
48
|
-
...(height !== undefined ? { height } : {}),
|
|
49
|
-
},
|
|
50
|
-
...(alt !== undefined ? { alt } : {}),
|
|
51
|
-
...(credit !== undefined ? { credit } : {}),
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
const encodeThumbnails = (mainImage, thumbnails, field) => {
|
|
55
|
-
var _a, _b, _c;
|
|
56
|
-
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) => ({
|
|
57
|
-
...acc,
|
|
58
|
-
[thumbnail.name]: encodeImageField(thumbnails[thumbnail.name], mainImage, thumbnail),
|
|
59
|
-
}), {})) !== null && _c !== void 0 ? _c : {};
|
|
60
|
-
};
|
|
61
|
-
const ImageFieldWithThumbnails = (field) => new t.Type("ImageFieldWithThumbnails", (u) => ImageFieldValidator.is(u) &&
|
|
62
|
-
"thumbnails" in u &&
|
|
63
|
-
ThumbnailsValidator.is(u["thumbnails"]), (u, ctx) => {
|
|
64
|
-
return (0, function_1.pipe)(ImageFieldValidator.validate(u, ctx), (0, Either_1.chain)((mainImage) => {
|
|
65
|
-
const { id, dimensions, edit, credit, alt, ...maybeThumbnails } = mainImage;
|
|
66
|
-
return (0, function_1.pipe)(ThumbnailsValidator.validate(maybeThumbnails, ctx), (0, Either_1.map)((thumbnails) => {
|
|
67
|
-
var _a;
|
|
68
|
-
return ({
|
|
69
|
-
...encodeImageField(mainImage, mainImage, (_a = field === null || field === void 0 ? void 0 : field.config) === null || _a === void 0 ? void 0 : _a.constraint),
|
|
70
|
-
thumbnails: encodeThumbnails(mainImage, thumbnails, field),
|
|
71
|
-
});
|
|
72
|
-
}));
|
|
73
|
-
}));
|
|
74
|
-
}, t.identity);
|
|
75
|
-
const ImportImage = (field) => (0, ImportContent_1.ImportContent)("Image", (0, validators_1.NullOrElse)(ImageFieldWithThumbnails(field)));
|
|
76
|
-
exports.ImportImage = ImportImage;
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { chain, map } from "fp-ts/Either"
|
|
2
|
-
import { pipe } from "fp-ts/lib/function"
|
|
3
|
-
import type { Validation } from "io-ts"
|
|
4
|
-
import * as t from "io-ts"
|
|
5
|
-
|
|
6
|
-
import type { Image } from "../../../../customtypes"
|
|
7
|
-
import type ImageConstraint from "../../../../customtypes/widgets/shared/ImageConstraint"
|
|
8
|
-
import { NullOrElse } from "../../../../validators"
|
|
9
|
-
import {
|
|
10
|
-
AnyObject,
|
|
11
|
-
Number,
|
|
12
|
-
String,
|
|
13
|
-
StringOrNull,
|
|
14
|
-
} from "../../../../validators/BasicTypes"
|
|
15
|
-
import { ImportContent } from "../ImportContent"
|
|
16
|
-
|
|
17
|
-
const ImageFieldValidator = AnyObject.pipe(
|
|
18
|
-
t.intersection([
|
|
19
|
-
t.type({
|
|
20
|
-
id: String,
|
|
21
|
-
}),
|
|
22
|
-
t.partial({
|
|
23
|
-
dimensions: AnyObject.pipe(
|
|
24
|
-
t.partial({
|
|
25
|
-
width: Number,
|
|
26
|
-
height: Number,
|
|
27
|
-
}),
|
|
28
|
-
),
|
|
29
|
-
edit: AnyObject.pipe(
|
|
30
|
-
t.partial({
|
|
31
|
-
x: Number,
|
|
32
|
-
y: Number,
|
|
33
|
-
zoom: Number,
|
|
34
|
-
background: String,
|
|
35
|
-
}),
|
|
36
|
-
),
|
|
37
|
-
credit: StringOrNull,
|
|
38
|
-
alt: StringOrNull,
|
|
39
|
-
}),
|
|
40
|
-
]),
|
|
41
|
-
)
|
|
42
|
-
|
|
43
|
-
const ThumbnailsValidator = t.record(t.string, ImageFieldValidator)
|
|
44
|
-
|
|
45
|
-
export type ImageField = {
|
|
46
|
-
id: string
|
|
47
|
-
edit: {
|
|
48
|
-
x: number
|
|
49
|
-
y: number
|
|
50
|
-
zoom: number
|
|
51
|
-
background?: string
|
|
52
|
-
}
|
|
53
|
-
dimensions: {
|
|
54
|
-
width?: number
|
|
55
|
-
height?: number
|
|
56
|
-
}
|
|
57
|
-
credit?: string | null
|
|
58
|
-
alt?: string | null
|
|
59
|
-
}
|
|
60
|
-
type ImageFieldWithThumbnails = ImageField & {
|
|
61
|
-
thumbnails: Record<string, ImageField>
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const encodeImageField = (
|
|
65
|
-
image: t.TypeOf<typeof ImageFieldValidator> | undefined,
|
|
66
|
-
mainImage: t.TypeOf<typeof ImageFieldValidator>,
|
|
67
|
-
constraints?: ImageConstraint,
|
|
68
|
-
): ImageField => {
|
|
69
|
-
const background = image?.edit?.background
|
|
70
|
-
const width =
|
|
71
|
-
constraints?.width ??
|
|
72
|
-
image?.dimensions?.width ??
|
|
73
|
-
mainImage.dimensions?.width
|
|
74
|
-
const height =
|
|
75
|
-
constraints?.height ??
|
|
76
|
-
image?.dimensions?.height ??
|
|
77
|
-
mainImage.dimensions?.height
|
|
78
|
-
const alt = image?.alt
|
|
79
|
-
const credit = image?.credit
|
|
80
|
-
|
|
81
|
-
return {
|
|
82
|
-
id: image?.id ?? mainImage?.id,
|
|
83
|
-
edit: {
|
|
84
|
-
x: image?.edit?.x ?? 0,
|
|
85
|
-
y: image?.edit?.y ?? 0,
|
|
86
|
-
zoom: image?.edit?.zoom ?? 1,
|
|
87
|
-
...(background !== undefined ? { background } : {}),
|
|
88
|
-
},
|
|
89
|
-
dimensions: {
|
|
90
|
-
...(width !== undefined ? { width } : {}),
|
|
91
|
-
...(height !== undefined ? { height } : {}),
|
|
92
|
-
},
|
|
93
|
-
...(alt !== undefined ? { alt } : {}),
|
|
94
|
-
...(credit !== undefined ? { credit } : {}),
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const encodeThumbnails = (
|
|
99
|
-
mainImage: t.TypeOf<typeof ImageFieldValidator>,
|
|
100
|
-
thumbnails: t.TypeOf<typeof ThumbnailsValidator>,
|
|
101
|
-
field?: Image,
|
|
102
|
-
) =>
|
|
103
|
-
field?.config?.thumbnails?.reduce(
|
|
104
|
-
(acc, thumbnail) => ({
|
|
105
|
-
...acc,
|
|
106
|
-
[thumbnail.name]: encodeImageField(
|
|
107
|
-
thumbnails[thumbnail.name],
|
|
108
|
-
mainImage,
|
|
109
|
-
thumbnail,
|
|
110
|
-
),
|
|
111
|
-
}),
|
|
112
|
-
{},
|
|
113
|
-
) ?? {}
|
|
114
|
-
|
|
115
|
-
const ImageFieldWithThumbnails = (field?: Image) =>
|
|
116
|
-
new t.Type<ImageFieldWithThumbnails>(
|
|
117
|
-
"ImageFieldWithThumbnails",
|
|
118
|
-
(u: unknown): u is ImageFieldWithThumbnails =>
|
|
119
|
-
ImageFieldValidator.is(u) &&
|
|
120
|
-
"thumbnails" in u &&
|
|
121
|
-
ThumbnailsValidator.is(u["thumbnails"]),
|
|
122
|
-
(u: unknown, ctx): Validation<ImageFieldWithThumbnails> => {
|
|
123
|
-
return pipe(
|
|
124
|
-
ImageFieldValidator.validate(u, ctx),
|
|
125
|
-
chain((mainImage) => {
|
|
126
|
-
const { id, dimensions, edit, credit, alt, ...maybeThumbnails } =
|
|
127
|
-
mainImage
|
|
128
|
-
return pipe(
|
|
129
|
-
ThumbnailsValidator.validate(maybeThumbnails, ctx),
|
|
130
|
-
map((thumbnails) => ({
|
|
131
|
-
...encodeImageField(
|
|
132
|
-
mainImage,
|
|
133
|
-
mainImage,
|
|
134
|
-
field?.config?.constraint,
|
|
135
|
-
),
|
|
136
|
-
thumbnails: encodeThumbnails(mainImage, thumbnails, field),
|
|
137
|
-
})),
|
|
138
|
-
)
|
|
139
|
-
}),
|
|
140
|
-
)
|
|
141
|
-
},
|
|
142
|
-
t.identity,
|
|
143
|
-
)
|
|
144
|
-
|
|
145
|
-
export const ImportImage = (field?: Image) =>
|
|
146
|
-
ImportContent("Image", NullOrElse(ImageFieldWithThumbnails(field)))
|
|
147
|
-
export type ImportImage = t.TypeOf<ReturnType<typeof ImportImage>>
|