@prismicio/types-internal 2.2.0-alpha.8 → 2.2.0-alpha.9

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.
@@ -4,7 +4,7 @@ exports.imageConverter = void 0;
4
4
  const common_1 = require("../../../../common");
5
5
  const Objects_1 = require("../../../../utils/Objects");
6
6
  function convertImage(imageField, image) {
7
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
7
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
8
8
  return (0, Objects_1.withOptionals)({
9
9
  origin: {
10
10
  id: image.id,
@@ -15,17 +15,17 @@ function convertImage(imageField, image) {
15
15
  },
16
16
  // All images returned form Asset API should have width and height properties.
17
17
  // Image width and height will be only applied if there are no constraints and user didn't overwrite it
18
- width: (_d = (_c = imageField === null || imageField === void 0 ? void 0 : imageField.width) !== null && _c !== void 0 ? _c : image.width) !== null && _d !== void 0 ? _d : 0,
19
- height: (_f = (_e = imageField === null || imageField === void 0 ? void 0 : imageField.height) !== null && _e !== void 0 ? _e : image.height) !== null && _f !== void 0 ? _f : 0,
18
+ width: (_e = (_d = (_c = imageField === null || imageField === void 0 ? void 0 : imageField.dimensions) === null || _c === void 0 ? void 0 : _c.width) !== null && _d !== void 0 ? _d : image.width) !== null && _e !== void 0 ? _e : 0,
19
+ height: (_h = (_g = (_f = imageField === null || imageField === void 0 ? void 0 : imageField.dimensions) === null || _f === void 0 ? void 0 : _f.height) !== null && _g !== void 0 ? _g : image.height) !== null && _h !== void 0 ? _h : 0,
20
20
  // If edit is not provided, we crop constraint width and height from the left upper corner.
21
21
  // WARN: If constraints are greater than image dimensions cut outside the image (background will fill extra space).
22
22
  edit: {
23
- zoom: (_h = (_g = imageField.edit) === null || _g === void 0 ? void 0 : _g.zoom) !== null && _h !== void 0 ? _h : 1,
23
+ zoom: (_k = (_j = imageField.edit) === null || _j === void 0 ? void 0 : _j.zoom) !== null && _k !== void 0 ? _k : 1,
24
24
  crop: {
25
- x: (_k = (_j = imageField.edit) === null || _j === void 0 ? void 0 : _j.x) !== null && _k !== void 0 ? _k : 0,
26
- y: (_m = (_l = imageField.edit) === null || _l === void 0 ? void 0 : _l.y) !== null && _m !== void 0 ? _m : 0,
25
+ x: (_m = (_l = imageField.edit) === null || _l === void 0 ? void 0 : _l.x) !== null && _m !== void 0 ? _m : 0,
26
+ y: (_p = (_o = imageField.edit) === null || _o === void 0 ? void 0 : _o.y) !== null && _p !== void 0 ? _p : 0,
27
27
  },
28
- background: (_p = (_o = imageField.edit) === null || _o === void 0 ? void 0 : _o.background) !== null && _p !== void 0 ? _p : (image.extension === "png" ? "transparent" : "#ffffff"),
28
+ background: (_r = (_q = imageField.edit) === null || _q === void 0 ? void 0 : _q.background) !== null && _r !== void 0 ? _r : (image.extension === "png" ? "transparent" : "#ffffff"),
29
29
  },
30
30
  url: image.url,
31
31
  }, [
@@ -1,14 +1,16 @@
1
1
  import * as t from "io-ts";
2
2
  export declare type ImageField = {
3
3
  id: string;
4
- width?: number;
5
- height?: number;
6
4
  edit: {
7
5
  x: number;
8
6
  y: number;
9
7
  zoom: number;
10
8
  background?: string;
11
9
  };
10
+ dimensions: {
11
+ width?: number;
12
+ height?: number;
13
+ };
12
14
  credit?: string | null;
13
15
  alt?: string | null;
14
16
  };
@@ -6,43 +6,47 @@ const Either_1 = require("fp-ts/Either");
6
6
  const function_1 = require("fp-ts/lib/function");
7
7
  const t = (0, tslib_1.__importStar)(require("io-ts"));
8
8
  const validators_1 = require("../../../../validators");
9
- const validators_2 = require("../../../../validators");
9
+ const BasicTypes_1 = require("../../../../validators/BasicTypes");
10
10
  const ImportContent_1 = require("../ImportContent");
11
- const ImageFieldValidator = validators_1.AnyObject.pipe(t.intersection([
11
+ const ImageFieldValidator = BasicTypes_1.AnyObject.pipe(t.intersection([
12
12
  t.type({
13
- id: validators_2.String,
13
+ id: BasicTypes_1.String,
14
14
  }),
15
15
  t.partial({
16
- width: validators_1.Number,
17
- height: validators_1.Number,
18
- edit: validators_1.AnyObject.pipe(t.partial({
19
- x: validators_1.Number,
20
- y: validators_1.Number,
21
- zoom: validators_1.Number,
22
- background: validators_2.String,
16
+ dimensions: BasicTypes_1.AnyObject.pipe(t.partial({
17
+ width: BasicTypes_1.Number,
18
+ height: BasicTypes_1.Number,
23
19
  })),
24
- credit: validators_2.StringOrNull,
25
- alt: validators_2.StringOrNull,
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,
26
28
  }),
27
29
  ]));
28
30
  const ThumbnailsValidator = t.record(t.string, ImageFieldValidator);
29
31
  const encodeImageField = (image, mainImage, constraints) => {
30
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
32
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
31
33
  const background = (_a = image === null || image === void 0 ? void 0 : image.edit) === null || _a === void 0 ? void 0 : _a.background;
32
- const width = (_b = constraints === null || constraints === void 0 ? void 0 : constraints.width) !== null && _b !== void 0 ? _b : image === null || image === void 0 ? void 0 : image.width;
33
- const height = (_c = constraints === null || constraints === void 0 ? void 0 : constraints.height) !== null && _c !== void 0 ? _c : image === null || image === void 0 ? void 0 : image.height;
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;
34
36
  const alt = image === null || image === void 0 ? void 0 : image.alt;
35
37
  const credit = image === null || image === void 0 ? void 0 : image.credit;
36
38
  return {
37
- id: (_d = image === null || image === void 0 ? void 0 : image.id) !== null && _d !== void 0 ? _d : mainImage === null || mainImage === void 0 ? void 0 : mainImage.id,
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,
38
40
  edit: {
39
- x: (_f = (_e = image === null || image === void 0 ? void 0 : image.edit) === null || _e === void 0 ? void 0 : _e.x) !== null && _f !== void 0 ? _f : 0,
40
- y: (_h = (_g = image === null || image === void 0 ? void 0 : image.edit) === null || _g === void 0 ? void 0 : _g.y) !== null && _h !== void 0 ? _h : 0,
41
- zoom: (_k = (_j = image === null || image === void 0 ? void 0 : image.edit) === null || _j === void 0 ? void 0 : _j.zoom) !== null && _k !== void 0 ? _k : 1,
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,
42
44
  ...(background !== undefined ? { background } : {}),
43
45
  },
44
- ...(width !== undefined ? { width } : {}),
45
- ...(height !== undefined ? { height } : {}),
46
+ dimensions: {
47
+ ...(width !== undefined ? { width } : {}),
48
+ ...(height !== undefined ? { height } : {}),
49
+ },
46
50
  ...(alt !== undefined ? { alt } : {}),
47
51
  ...(credit !== undefined ? { credit } : {}),
48
52
  };
@@ -58,7 +62,7 @@ const ImageFieldWithThumbnails = (field) => new t.Type("ImageFieldWithThumbnails
58
62
  "thumbnails" in u &&
59
63
  ThumbnailsValidator.is(u["thumbnails"]), (u, ctx) => {
60
64
  return (0, function_1.pipe)(ImageFieldValidator.validate(u, ctx), (0, Either_1.chain)((mainImage) => {
61
- const { id, width, height, edit, credit, alt, ...maybeThumbnails } = mainImage;
65
+ const { id, dimensions, edit, credit, alt, ...maybeThumbnails } = mainImage;
62
66
  return (0, function_1.pipe)(ThumbnailsValidator.validate(maybeThumbnails, ctx), (0, Either_1.map)((thumbnails) => {
63
67
  var _a;
64
68
  return ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/types-internal",
3
- "version": "2.2.0-alpha.8",
3
+ "version": "2.2.0-alpha.9",
4
4
  "description": "Prismic types for Custom Types and Prismic Data",
5
5
  "keywords": [
6
6
  "typescript",
@@ -16,8 +16,8 @@ function convertImage(imageField: ImageField, image: Asset) {
16
16
  },
17
17
  // All images returned form Asset API should have width and height properties.
18
18
  // Image width and height will be only applied if there are no constraints and user didn't overwrite it
19
- width: imageField?.width ?? image.width ?? 0,
20
- height: imageField?.height ?? image.height ?? 0,
19
+ width: imageField?.dimensions?.width ?? image.width ?? 0,
20
+ height: imageField?.dimensions?.height ?? image.height ?? 0,
21
21
  // If edit is not provided, we crop constraint width and height from the left upper corner.
22
22
  // WARN: If constraints are greater than image dimensions cut outside the image (background will fill extra space).
23
23
  edit: {
@@ -5,8 +5,13 @@ import * as t from "io-ts"
5
5
 
6
6
  import type { Image } from "../../../../customtypes"
7
7
  import type ImageConstraint from "../../../../customtypes/widgets/shared/ImageConstraint"
8
- import { AnyObject, NullOrElse, Number } from "../../../../validators"
9
- import { String, StringOrNull } from "../../../../validators"
8
+ import { NullOrElse } from "../../../../validators"
9
+ import {
10
+ AnyObject,
11
+ Number,
12
+ String,
13
+ StringOrNull,
14
+ } from "../../../../validators/BasicTypes"
10
15
  import { ImportContent } from "../ImportContent"
11
16
 
12
17
  const ImageFieldValidator = AnyObject.pipe(
@@ -15,8 +20,12 @@ const ImageFieldValidator = AnyObject.pipe(
15
20
  id: String,
16
21
  }),
17
22
  t.partial({
18
- width: Number,
19
- height: Number,
23
+ dimensions: AnyObject.pipe(
24
+ t.partial({
25
+ width: Number,
26
+ height: Number,
27
+ }),
28
+ ),
20
29
  edit: AnyObject.pipe(
21
30
  t.partial({
22
31
  x: Number,
@@ -35,14 +44,16 @@ const ThumbnailsValidator = t.record(t.string, ImageFieldValidator)
35
44
 
36
45
  export type ImageField = {
37
46
  id: string
38
- width?: number
39
- height?: number
40
47
  edit: {
41
48
  x: number
42
49
  y: number
43
50
  zoom: number
44
51
  background?: string
45
52
  }
53
+ dimensions: {
54
+ width?: number
55
+ height?: number
56
+ }
46
57
  credit?: string | null
47
58
  alt?: string | null
48
59
  }
@@ -56,8 +67,14 @@ const encodeImageField = (
56
67
  constraints?: ImageConstraint,
57
68
  ): ImageField => {
58
69
  const background = image?.edit?.background
59
- const width = constraints?.width ?? image?.width
60
- const height = constraints?.height ?? image?.height
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
61
78
  const alt = image?.alt
62
79
  const credit = image?.credit
63
80
 
@@ -69,8 +86,10 @@ const encodeImageField = (
69
86
  zoom: image?.edit?.zoom ?? 1,
70
87
  ...(background !== undefined ? { background } : {}),
71
88
  },
72
- ...(width !== undefined ? { width } : {}),
73
- ...(height !== undefined ? { height } : {}),
89
+ dimensions: {
90
+ ...(width !== undefined ? { width } : {}),
91
+ ...(height !== undefined ? { height } : {}),
92
+ },
74
93
  ...(alt !== undefined ? { alt } : {}),
75
94
  ...(credit !== undefined ? { credit } : {}),
76
95
  }
@@ -104,7 +123,7 @@ const ImageFieldWithThumbnails = (field?: Image) =>
104
123
  return pipe(
105
124
  ImageFieldValidator.validate(u, ctx),
106
125
  chain((mainImage) => {
107
- const { id, width, height, edit, credit, alt, ...maybeThumbnails } =
126
+ const { id, dimensions, edit, credit, alt, ...maybeThumbnails } =
108
127
  mainImage
109
128
  return pipe(
110
129
  ThumbnailsValidator.validate(maybeThumbnails, ctx),