@prismicio/types-internal 2.2.0-alpha.21 → 2.2.0-alpha.22

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.
Files changed (29) hide show
  1. package/lib/content/fields/nestable/RichTextContent/Blocks.d.ts +0 -23
  2. package/lib/content/fields/nestable/RichTextContent/Blocks.js +5 -5
  3. package/lib/import/converters/fields/nestable/Image.d.ts +2 -2
  4. package/lib/import/converters/fields/nestable/Image.js +24 -22
  5. package/lib/import/converters/fields/nestable/index.d.ts +1 -1
  6. package/lib/import/converters/fields/nestable/index.js +1 -1
  7. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.d.ts +16 -2
  8. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.js +7 -5
  9. package/package.json +1 -1
  10. package/src/content/fields/nestable/RichTextContent/Blocks.ts +1 -1
  11. package/src/import/converters/fields/nestable/Image.ts +22 -14
  12. package/src/import/converters/fields/nestable/RichText.ts +62 -0
  13. package/src/import/converters/fields/nestable/index.ts +1 -1
  14. package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.ts +9 -5
  15. package/lib/import/converters/fields/nestable/GeoPoint.d.ts +0 -3
  16. package/lib/import/converters/fields/nestable/GeoPoint.js +0 -15
  17. package/lib/import/converters/fields/nestable/RichText/embedBlock.d.ts +0 -4
  18. package/lib/import/converters/fields/nestable/RichText/embedBlock.js +0 -14
  19. package/lib/import/converters/fields/nestable/RichText/imageBlock.d.ts +0 -4
  20. package/lib/import/converters/fields/nestable/RichText/imageBlock.js +0 -12
  21. package/lib/import/converters/fields/nestable/RichText/index.d.ts +0 -4
  22. package/lib/import/converters/fields/nestable/RichText/index.js +0 -22
  23. package/lib/import/converters/fields/nestable/RichText/textBlock.d.ts +0 -4
  24. package/lib/import/converters/fields/nestable/RichText/textBlock.js +0 -34
  25. package/src/import/converters/fields/nestable/RichText/embedBlock.ts +0 -14
  26. package/src/import/converters/fields/nestable/RichText/imageBlock.ts +0 -14
  27. package/src/import/converters/fields/nestable/RichText/index.ts +0 -23
  28. package/src/import/converters/fields/nestable/RichText/textBlock.ts +0 -35
  29. /package/src/import/converters/fields/nestable/{GeoPoint.ts → GeooPoint.ts} +0 -0
@@ -214,29 +214,6 @@ export declare const TextBlock: t.ExactC<t.IntersectionC<[t.TypeC<{
214
214
  direction: t.StringC;
215
215
  }>]>>;
216
216
  export declare type TextBlock = t.TypeOf<typeof TextBlock>;
217
- export declare const TextBlockLegacy: t.ExactC<t.IntersectionC<[t.TypeC<{
218
- type: t.Type<"image" | "paragraph" | "heading1" | "heading2" | "heading3" | "heading4" | "heading5" | "heading6" | "strong" | "em" | "preformatted" | "hyperlink" | "embed" | "list-item" | "o-list-item" | "rtl", "image" | "paragraph" | "heading1" | "heading2" | "heading3" | "heading4" | "heading5" | "heading6" | "strong" | "em" | "preformatted" | "hyperlink" | "embed" | "list-item" | "o-list-item" | "rtl", unknown>;
219
- content: t.IntersectionC<[t.TypeC<{
220
- text: t.StringC;
221
- }>, t.PartialC<{
222
- spans: t.Type<({
223
- data?: unknown;
224
- } & {
225
- start: number;
226
- end: number;
227
- type: "image" | "label" | "paragraph" | "heading1" | "heading2" | "heading3" | "heading4" | "heading5" | "heading6" | "strong" | "em" | "preformatted" | "hyperlink" | "embed" | "list-item" | "o-list-item" | "rtl";
228
- })[], ({
229
- data?: unknown;
230
- } & {
231
- start: number;
232
- end: number;
233
- type: "image" | "label" | "paragraph" | "heading1" | "heading2" | "heading3" | "heading4" | "heading5" | "heading6" | "strong" | "em" | "preformatted" | "hyperlink" | "embed" | "list-item" | "o-list-item" | "rtl";
234
- })[], unknown>;
235
- }>]>;
236
- }>, t.PartialC<{
237
- label: t.StringC;
238
- direction: t.StringC;
239
- }>]>>;
240
217
  export declare const BlockLegacy: t.Type<({
241
218
  type: "image";
242
219
  data: {
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Block = exports.BlockLegacy = exports.TextBlockLegacy = exports.TextBlock = exports.checkEmbedBlock = exports.EmbedBlock = exports.checkImageBlock = exports.ImageBlock = exports.ValidatedMetas = exports.Span = exports.Meta = void 0;
3
+ exports.Block = exports.BlockLegacy = exports.TextBlock = exports.checkEmbedBlock = exports.EmbedBlock = exports.checkImageBlock = exports.ImageBlock = exports.ValidatedMetas = exports.Span = exports.Meta = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const fp_ts_1 = require("fp-ts");
6
6
  const Either_1 = require("fp-ts/lib/Either");
@@ -144,20 +144,20 @@ const TextBlockCodec = (linkCodec) => t.exact(t.intersection([
144
144
  }),
145
145
  ]));
146
146
  exports.TextBlock = TextBlockCodec(LinkContent_1.Link);
147
- exports.TextBlockLegacy = TextBlockCodec(LinkContent_1.LinkLegacy);
147
+ const TextBlockLegacy = TextBlockCodec(LinkContent_1.LinkLegacy);
148
148
  const legacyBlockCodec = t.union([
149
149
  EmbedBlockLegacy,
150
150
  ImageBlockLegacy,
151
- exports.TextBlockLegacy,
151
+ TextBlockLegacy,
152
152
  ]);
153
- exports.BlockLegacy = new t.Type("BlockLegacy", (u) => EmbedBlockLegacy.is(u) || ImageBlockLegacy.is(u) || exports.TextBlockLegacy.is(u), (legacyBlock) => legacyBlockCodec.decode(legacyBlock), (block) => {
153
+ exports.BlockLegacy = new t.Type("BlockLegacy", (u) => EmbedBlockLegacy.is(u) || ImageBlockLegacy.is(u) || TextBlockLegacy.is(u), (legacyBlock) => legacyBlockCodec.decode(legacyBlock), (block) => {
154
154
  return (() => {
155
155
  if (exports.ImageBlock.is(block))
156
156
  return ImageBlockLegacy.encode(block);
157
157
  else if (exports.EmbedBlock.is(block))
158
158
  return EmbedBlockLegacy.encode(block);
159
159
  else
160
- return exports.TextBlockLegacy.encode(block);
160
+ return TextBlockLegacy.encode(block);
161
161
  })();
162
162
  });
163
163
  exports.Block = t.union([exports.ImageBlock, exports.EmbedBlock, exports.TextBlock]);
@@ -1,6 +1,6 @@
1
1
  import type { Asset } from "../../../../common";
2
2
  import type { ImageContent, ImageContentView } from "../../../../content";
3
- import type { ImageField, ImportImage } from "../../../validators";
3
+ import type { ImportImage } from "../../../validators";
4
4
  import type { ImportImageBlock } from "../../../validators/fields/nestable/ImportRichText/blocks";
5
- export declare function convertImageView<Input extends ImageField | ImportImageBlock>(inputImage: Input, image: Asset): ImageContentView;
5
+ export declare const imageBlockConverter: (imageBlock: ImportImageBlock, assets: Record<Asset["id"], Asset | undefined>) => ImageContentView;
6
6
  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.convertImageView = 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 convertImageView(inputImage, image) {
7
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
6
+ function convertImage(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: "edit" in inputImage
12
- ? inputImage.edit
13
- : {
14
- x: 0,
15
- y: 0,
16
- zoom: 1,
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: (_a = image.width) !== null && _a !== void 0 ? _a : 0,
26
- height: (_b = image.height) !== null && _b !== void 0 ? _b : 0,
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: (_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,
31
- 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,
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: (_k = (_j = imageField.edit) === null || _j === void 0 ? void 0 : _j.zoom) !== null && _k !== void 0 ? _k : 1,
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: (_m = (_l = imageField.edit) === null || _l === void 0 ? void 0 : _l.x) !== null && _m !== void 0 ? _m : 0,
38
- y: (_p = (_o = imageField.edit) === null || _o === void 0 ? void 0 : _o.y) !== null && _p !== void 0 ? _p : 0,
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: (_r = (_q = imageField.edit) === null || _q === void 0 ? void 0 : _q.background) !== null && _r !== void 0 ? _r : (image.extension === "png" ? "transparent" : "#ffffff"),
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,22 +44,25 @@ function convertImageView(inputImage, image) {
45
44
  ["credits", (imageField === null || imageField === void 0 ? void 0 : imageField.copyright) || image.credits],
46
45
  ]);
47
46
  }
48
- exports.convertImageView = convertImageView;
49
47
  function convertThumbnails(imageField, assets) {
50
48
  return Object.entries(imageField.thumbnails).reduce((acc, [thumbnailName, thumbnail]) => {
51
49
  return {
52
50
  ...acc,
53
- [thumbnailName]: convertImageView(thumbnail, (0, common_1.getAssetOrThrow)(assets)(thumbnail.id)),
51
+ [thumbnailName]: convertImage(thumbnail, (0, common_1.getAssetOrThrow)(assets)(thumbnail.id)),
54
52
  };
55
53
  }, {});
56
54
  }
55
+ const imageBlockConverter = (imageBlock, assets) => {
56
+ return convertImage(imageBlock, (0, common_1.getAssetOrThrow)(assets)(imageBlock.id));
57
+ };
58
+ exports.imageBlockConverter = imageBlockConverter;
57
59
  // All assets from `imageField` must be present in `assets`
58
60
  // If not then function will throw an error
59
61
  const imageConverter = (imageField, assets) => {
60
62
  if (!imageField)
61
63
  return;
62
64
  return {
63
- ...convertImageView(imageField, (0, common_1.getAssetOrThrow)(assets)(imageField.id)),
65
+ ...convertImage(imageField, (0, common_1.getAssetOrThrow)(assets)(imageField.id)),
64
66
  thumbnails: convertThumbnails(imageField, assets),
65
67
  __TYPE__: "ImageContent",
66
68
  };
@@ -2,7 +2,7 @@ export * from "./Boolean";
2
2
  export * from "./Color";
3
3
  export * from "./Date";
4
4
  export * from "./Embed";
5
- export * from "./GeoPoint";
5
+ export * from "./GeooPoint";
6
6
  export * from "./Image";
7
7
  export * from "./Link";
8
8
  export * from "./Nestable";
@@ -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("./GeoPoint"), exports);
8
+ (0, tslib_1.__exportStar)(require("./GeooPoint"), 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);
@@ -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("../../../../../../validators");
6
+ const validators_1 = require("../../Image/validators");
7
7
  exports.ImportImageBlockType = t.literal("image");
8
- exports.ImportImageBlock = t.strict({
9
- type: exports.ImportImageBlockType,
10
- id: validators_1.String,
11
- });
8
+ exports.ImportImageBlock = t.exact(t.intersection([
9
+ t.type({
10
+ type: exports.ImportImageBlockType,
11
+ }),
12
+ validators_1.ImportImageView,
13
+ ]));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/types-internal",
3
- "version": "2.2.0-alpha.21",
3
+ "version": "2.2.0-alpha.22",
4
4
  "description": "Prismic types for Custom Types and Prismic Data",
5
5
  "keywords": [
6
6
  "typescript",
@@ -198,7 +198,7 @@ const TextBlockCodec = (linkCodec: LinkCodec) =>
198
198
  export const TextBlock = TextBlockCodec(Link)
199
199
  export type TextBlock = t.TypeOf<typeof TextBlock>
200
200
 
201
- export const TextBlockLegacy = TextBlockCodec(LinkLegacy)
201
+ const TextBlockLegacy = TextBlockCodec(LinkLegacy)
202
202
  type TextBlockLegacy = t.TypeOf<typeof TextBlockLegacy>
203
203
 
204
204
  const legacyBlockCodec = t.union([
@@ -3,24 +3,22 @@ import { getAssetOrThrow } from "../../../../common"
3
3
  import type { ImageContent, ImageContentView } from "../../../../content"
4
4
  import { withOptionals } from "../../../../utils/Objects"
5
5
  import type { ImageField, ImportImage } from "../../../validators"
6
- import type { ImportImageBlock } from "../../../validators/fields/nestable/ImportRichText/blocks";
6
+ import type { ImportImageBlock } from "../../../validators/fields/nestable/ImportRichText/blocks"
7
7
 
8
- export function convertImageView<Input extends ImageField | ImportImageBlock>(
8
+ function convertImage<Input extends ImageField | ImportImageBlock>(
9
9
  inputImage: Input,
10
10
  image: Asset,
11
- ): ImageContentView {
11
+ ) {
12
12
  // We can do that because anyway all properties being read
13
13
  const imageField: ImageField = {
14
14
  ...inputImage,
15
- edit:
16
- "edit" in inputImage
17
- ? inputImage.edit
18
- : {
19
- x: 0,
20
- y: 0,
21
- zoom: 1,
22
- },
23
- dimensions: "dimensions" in inputImage ? inputImage.dimensions : {},
15
+ edit: {
16
+ x: 0,
17
+ y: 0,
18
+ zoom: 1,
19
+ ...inputImage.edit,
20
+ },
21
+ dimensions: inputImage.dimensions ?? {},
24
22
  }
25
23
  return withOptionals<ImageContentView>(
26
24
  {
@@ -64,7 +62,7 @@ function convertThumbnails(
64
62
  (acc, [thumbnailName, thumbnail]) => {
65
63
  return {
66
64
  ...acc,
67
- [thumbnailName]: convertImageView(
65
+ [thumbnailName]: convertImage(
68
66
  thumbnail,
69
67
  getAssetOrThrow(assets)(thumbnail.id),
70
68
  ),
@@ -74,6 +72,16 @@ function convertThumbnails(
74
72
  )
75
73
  }
76
74
 
75
+ export const imageBlockConverter = (
76
+ imageBlock: ImportImageBlock,
77
+ assets: Record<Asset["id"], Asset | undefined>,
78
+ ): ImageContentView => {
79
+ return convertImage<ImportImageBlock>(
80
+ imageBlock,
81
+ getAssetOrThrow(assets)(imageBlock.id),
82
+ )
83
+ }
84
+
77
85
  // All assets from `imageField` must be present in `assets`
78
86
  // If not then function will throw an error
79
87
  export const imageConverter = (
@@ -83,7 +91,7 @@ export const imageConverter = (
83
91
  if (!imageField) return
84
92
 
85
93
  return {
86
- ...convertImageView<ImageField>(
94
+ ...convertImage<ImageField>(
87
95
  imageField,
88
96
  getAssetOrThrow(assets)(imageField.id),
89
97
  ),
@@ -0,0 +1,62 @@
1
+ import type { Asset, Embed } from "../../../../common"
2
+ import type { Block, RichTextContent } from "../../../../content"
3
+ import { RichTextContentType } from "../../../../content"
4
+ import type { ImportBlock, ImportRichText } from "../../../validators"
5
+ import { embedConverter } from "./Embed"
6
+ import { imageBlockConverter } from "./Image"
7
+ import { linkConverter } from "./Link"
8
+
9
+ const richTextBlockConverter = (
10
+ importBlock: ImportBlock,
11
+ assets: Record<Asset["id"], Asset | undefined>,
12
+ embeds: Record<string, Embed | undefined>,
13
+ ): Block => {
14
+ if (importBlock.type === "image") {
15
+ return {
16
+ type: importBlock.type,
17
+ data: imageBlockConverter(importBlock, assets),
18
+ }
19
+ } else if (importBlock.type === "embed") {
20
+ const embedData = embedConverter(importBlock.oembed, embeds)
21
+ if (!embedData) throw new Error("Failed to convert embed data")
22
+ return {
23
+ type: importBlock.type,
24
+ data: embedData,
25
+ }
26
+ } else {
27
+ // Text block
28
+ return {
29
+ type: importBlock.type,
30
+ direction: importBlock.direction ?? "ltr",
31
+ content: {
32
+ text: importBlock.text,
33
+ spans:
34
+ importBlock.spans?.map((span) => {
35
+ const linkData =
36
+ span.type === "hyperlink"
37
+ ? linkConverter(span.data, assets)
38
+ : undefined
39
+ return {
40
+ type: span.type,
41
+ start: span.start,
42
+ end: span.end,
43
+ data: linkData,
44
+ }
45
+ }) ?? [],
46
+ },
47
+ }
48
+ }
49
+ }
50
+ export const richTextConverter = (
51
+ richTextField: ImportRichText["value"],
52
+ assets: Record<Asset["id"], Asset | undefined>,
53
+ embeds: Record<string, Embed | undefined>,
54
+ ): RichTextContent | undefined => {
55
+ if (richTextField === null) return
56
+ return {
57
+ __TYPE__: RichTextContentType,
58
+ value: richTextField.map((block) =>
59
+ richTextBlockConverter(block, assets, embeds),
60
+ ),
61
+ }
62
+ }
@@ -2,7 +2,7 @@ export * from "./Boolean"
2
2
  export * from "./Color"
3
3
  export * from "./Date"
4
4
  export * from "./Embed"
5
- export * from "./GeoPoint"
5
+ export * from "./GeooPoint"
6
6
  export * from "./Image"
7
7
  export * from "./Link"
8
8
  export * from "./Nestable"
@@ -1,13 +1,17 @@
1
1
  import * as t from "io-ts"
2
2
 
3
- import { String } from "../../../../../../validators"
3
+ import { ImportImageView } from "../../Image/validators"
4
4
 
5
5
  export const ImportImageBlockType = t.literal("image")
6
6
  export type ImportImageBlockType = t.TypeOf<typeof ImportImageBlockType>
7
7
 
8
- export const ImportImageBlock = t.strict({
9
- type: ImportImageBlockType,
10
- id: String,
11
- })
8
+ export const ImportImageBlock = t.exact(
9
+ t.intersection([
10
+ t.type({
11
+ type: ImportImageBlockType,
12
+ }),
13
+ ImportImageView,
14
+ ]),
15
+ )
12
16
 
13
17
  export type ImportImageBlock = t.TypeOf<typeof ImportImageBlock>
@@ -1,3 +0,0 @@
1
- import type { GeoPointContent } from "../../../../content";
2
- import type { ImportGeoPoint } from "../../../validators";
3
- export declare const geopointConverter: (field: ImportGeoPoint["value"]) => GeoPointContent | undefined;
@@ -1,15 +0,0 @@
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,4 +0,0 @@
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;
@@ -1,14 +0,0 @@
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;
@@ -1,4 +0,0 @@
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;
@@ -1,12 +0,0 @@
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;
@@ -1,4 +0,0 @@
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;
@@ -1,22 +0,0 @@
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;
@@ -1,4 +0,0 @@
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;
@@ -1,34 +0,0 @@
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
- ...block.spans ? { spans: spansConverter(block.spans, assets) } : {}
11
- },
12
- ...block.direction ? { direction: block.direction } : {},
13
- };
14
- }
15
- exports.textBlockConverter = textBlockConverter;
16
- function spansConverter(spans, assets) {
17
- return spans.map(span => {
18
- var _a;
19
- if (span.type === 'hyperlink') {
20
- const { __TYPE__, ...data } = ((_a = (0, Link_1.linkConverter)(span.data, assets)) === null || _a === void 0 ? void 0 : _a.value) || {};
21
- return {
22
- type: span.type,
23
- start: span.start,
24
- end: span.end,
25
- data: data
26
- };
27
- }
28
- return {
29
- type: span.type,
30
- start: span.start,
31
- end: span.end
32
- };
33
- });
34
- }
@@ -1,14 +0,0 @@
1
- import type { Embed } from "../../../../../common"
2
- import type { EmbedBlock } from "../../../../../content";
3
- import type { ImportEmbedBlock } from "../../../../validators/fields/nestable/ImportRichText/blocks";
4
- import { embedConverter } from "../Embed";
5
-
6
- export function embedBlockConverter(block: ImportEmbedBlock, embeds: Record<string, Embed | undefined>): EmbedBlock {
7
- const embedData = embedConverter(block.oembed, embeds)
8
-
9
- if (!embedData) throw new Error("Failed to convert embed data")
10
- return {
11
- type: block.type,
12
- data: embedData,
13
- }
14
- }
@@ -1,14 +0,0 @@
1
- import { Asset, getAssetOrThrow } from "../../../../../common";
2
- import type { ImageBlock } from "../../../../../content";
3
- import type { ImportImageBlock } from "../../../../validators/fields/nestable/ImportRichText/blocks";
4
- import { convertImageView } from "../Image";
5
-
6
- export function imageBlockConverter(block: ImportImageBlock, assets: Record<Asset["id"], Asset | undefined>): ImageBlock {
7
- return {
8
- type: block.type,
9
- data: convertImageView<ImportImageBlock>(
10
- block,
11
- getAssetOrThrow(assets)(block.id)
12
- ),
13
- }
14
- }
@@ -1,23 +0,0 @@
1
- import type { Asset, Embed } from "../../../../../common"
2
- import type { RichTextContent } from "../../../../../content"
3
- import { RichTextContentType } from "../../../../../content"
4
- import type { ImportRichText } from "../../../../validators"
5
- import { embedBlockConverter } from "./embedBlock"
6
- import { imageBlockConverter } from "./imageBlock"
7
- import { textBlockConverter } from "./textBlock"
8
-
9
- export const richTextConverter = (
10
- richTextField: ImportRichText["value"],
11
- assets: Record<Asset["id"], Asset | undefined>,
12
- embeds: Record<string, Embed | undefined>,
13
- ): RichTextContent | undefined => {
14
- if (richTextField === null) return
15
- return {
16
- __TYPE__: RichTextContentType,
17
- value: richTextField.map((block) => {
18
- if (block.type === "image") return imageBlockConverter(block, assets)
19
- else if (block.type === "embed") return embedBlockConverter(block, embeds)
20
- return textBlockConverter(block, assets)
21
- }),
22
- }
23
- }
@@ -1,35 +0,0 @@
1
- import type { Asset } from "../../../../../common"
2
- import type { TextBlock } from "../../../../../content"
3
- import type { ImportTextBlock } from "../../../../validators/fields/nestable/ImportRichText/blocks"
4
- import { linkConverter } from "../Link"
5
-
6
- export function textBlockConverter(block: ImportTextBlock, assets: Record<Asset["id"], Asset | undefined>): TextBlock {
7
- return {
8
- type: block.type,
9
- content: {
10
- text: block.text,
11
- ...block.spans ? { spans: spansConverter(block.spans, assets) }: {}
12
- },
13
- ...block.direction ? { direction: block.direction } : {},
14
- }
15
- }
16
-
17
- function spansConverter(spans: NonNullable<ImportTextBlock['spans']>, assets: Record<Asset["id"], Asset | undefined>): TextBlock['content']['spans'] {
18
- return spans.map(span => {
19
- if (span.type === 'hyperlink') {
20
- const { __TYPE__, ...data } = linkConverter(span.data, assets)?.value || {}
21
- return {
22
- type: span.type,
23
- start: span.start,
24
- end: span.end,
25
- data: data
26
- }
27
- }
28
-
29
- return {
30
- type: span.type,
31
- start: span.start,
32
- end: span.end
33
- }
34
- })
35
- }