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

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 (31) hide show
  1. package/lib/content/Document.d.ts +936 -24
  2. package/lib/content/fields/GroupContent.d.ts +273 -7
  3. package/lib/content/fields/WidgetContent.d.ts +1248 -32
  4. package/lib/content/fields/nestable/NestableContent.d.ts +156 -4
  5. package/lib/content/fields/nestable/RichTextContent/Blocks.d.ts +582 -51
  6. package/lib/content/fields/nestable/RichTextContent/Blocks.js +32 -49
  7. package/lib/content/fields/nestable/RichTextContent/index.d.ts +195 -5
  8. package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +312 -8
  9. package/lib/content/fields/slices/Slice/RepeatableContent.d.ts +117 -3
  10. package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +312 -8
  11. package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +312 -8
  12. package/lib/content/fields/slices/Slice/index.d.ts +702 -18
  13. package/lib/content/fields/slices/SliceItem.d.ts +702 -18
  14. package/lib/content/fields/slices/SlicesContent.d.ts +936 -24
  15. package/lib/import/converters/fields/nestable/Image.d.ts +24 -2
  16. package/lib/import/converters/fields/nestable/Image.js +16 -17
  17. package/lib/import/converters/fields/nestable/RichText/textBlock.js +21 -14
  18. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.d.ts +16 -2
  19. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.js +7 -5
  20. package/package.json +1 -1
  21. package/src/content/fields/nestable/RichTextContent/Blocks.ts +48 -58
  22. package/src/import/converters/fields/nestable/Image.ts +9 -11
  23. package/src/import/converters/fields/nestable/RichText/embedBlock.ts +14 -11
  24. package/src/import/converters/fields/nestable/RichText/imageBlock.ts +15 -12
  25. package/src/import/converters/fields/nestable/RichText/index.ts +4 -4
  26. package/src/import/converters/fields/nestable/RichText/textBlock.ts +39 -26
  27. package/src/import/validators/fields/nestable/ImportRichText/blocks/ImportImageBlock.ts +9 -5
  28. package/lib/import/converters/fields/nestable/GeooPoint.d.ts +0 -3
  29. package/lib/import/converters/fields/nestable/GeooPoint.js +0 -15
  30. package/lib/import/converters/fields/nestable/RichText.d.ts +0 -4
  31. package/lib/import/converters/fields/nestable/RichText.js +0 -55
@@ -1,6 +1,28 @@
1
1
  import type { Asset } from "../../../../common";
2
- import type { ImageContent, ImageContentView } from "../../../../content";
2
+ import type { ImageContent } from "../../../../content";
3
3
  import type { ImageField, 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 function convertImageView<Input extends ImageField | ImportImageBlock>(inputImage: Input, image: Asset): {
6
+ origin: {
7
+ id: string;
8
+ url: string;
9
+ width: number;
10
+ height: number;
11
+ };
12
+ width: number;
13
+ height: number;
14
+ edit: {
15
+ zoom: number;
16
+ crop: {
17
+ x: number;
18
+ y: number;
19
+ };
20
+ background: string;
21
+ };
22
+ } & {
23
+ url?: string;
24
+ credits?: string | null;
25
+ alt?: string | null;
26
+ provider?: string | null | undefined;
27
+ };
6
28
  export declare const imageConverter: (imageField: ImportImage["value"], assets: Record<Asset["id"], Asset | undefined>) => ImageContent | undefined;
@@ -4,40 +4,39 @@ exports.imageConverter = exports.convertImageView = void 0;
4
4
  const common_1 = require("../../../../common");
5
5
  const Objects_1 = require("../../../../utils/Objects");
6
6
  function convertImageView(inputImage, image) {
7
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
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
  }, [
@@ -7,28 +7,35 @@ function textBlockConverter(block, assets) {
7
7
  type: block.type,
8
8
  content: {
9
9
  text: block.text,
10
- ...block.spans ? { spans: spansConverter(block.spans, assets) } : {}
10
+ ...(() => {
11
+ if (block.spans) {
12
+ const convertedSpans = spansConverter(block.spans, assets);
13
+ if (!convertedSpans)
14
+ return {};
15
+ return { spans: convertedSpans };
16
+ }
17
+ return {};
18
+ })(),
11
19
  },
12
- ...block.direction ? { direction: block.direction } : {},
20
+ ...(block.direction ? { direction: block.direction } : {}),
13
21
  };
14
22
  }
15
23
  exports.textBlockConverter = textBlockConverter;
16
24
  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
- }
25
+ return spans.map((span) => {
28
26
  return {
29
27
  type: span.type,
30
28
  start: span.start,
31
- end: span.end
29
+ end: span.end,
30
+ ...(() => {
31
+ if (span.type === "hyperlink") {
32
+ const convertedLinkContent = (0, Link_1.linkConverter)(span.data, assets);
33
+ if (!convertedLinkContent)
34
+ return {};
35
+ return { data: convertedLinkContent === null || convertedLinkContent === void 0 ? void 0 : convertedLinkContent.value };
36
+ }
37
+ return {};
38
+ })(),
32
39
  };
33
40
  });
34
41
  }
@@ -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.23",
4
4
  "description": "Prismic types for Custom Types and Prismic Data",
5
5
  "keywords": [
6
6
  "typescript",
@@ -1,5 +1,5 @@
1
1
  import { either } from "fp-ts"
2
- import { isLeft, isRight } from "fp-ts/lib/Either"
2
+ import { isRight } from "fp-ts/lib/Either"
3
3
  import { pipe } from "fp-ts/lib/function"
4
4
  import * as t from "io-ts"
5
5
 
@@ -18,66 +18,54 @@ import {
18
18
  import { ImageContentView } from "../ImageContent"
19
19
  import { Link, LinkLegacy } from "../LinkContent"
20
20
 
21
- export const Meta = t.exact(
22
- t.intersection([
23
- t.partial({
24
- data: t.unknown,
25
- }),
26
- t.type({
27
- start: t.number,
28
- end: t.number,
29
- type: t.union([RichTextNodeTypeCodec, t.literal("label")]),
30
- }),
31
- ]),
32
- )
33
- export type Meta = t.TypeOf<typeof Meta>
34
-
35
- // export alias for code clarity
36
- export const Span = Meta
37
- export type Span = Meta
38
-
39
- export const ValidatedMetas = (linkCodec: LinkCodec) =>
40
- new t.Type<Meta[], Meta[], unknown>(
41
- "ValidatedMetas",
42
- (metas): metas is Meta[] => Array.isArray(metas) && metas.every(Meta.is),
43
- (metas: unknown, c) => {
44
- if (Array.isArray(metas)) {
45
- const res = metas
46
- .reduce<Array<Meta>>((acc, maybeMeta) => {
47
- const maybeDecodedMeta = Meta.decode(maybeMeta)
48
- if (isRight(maybeDecodedMeta)) {
49
- const meta = maybeDecodedMeta.right
50
- // if it's an hyperlink it should have data validated as link otherwise we don't care and keep the meta
51
- if (meta.data && meta.type === "hyperlink") {
52
- const decoded = linkCodec.decode(meta.data)
53
- if (isLeft(decoded)) return acc
54
-
55
- return [...acc, { ...meta, data: decoded.right }]
56
- } else if (meta.type !== "hyperlink") {
57
- return [...acc, meta]
58
- }
59
- }
60
- return acc
21
+ const SpanFn = (linkCodec: typeof Link | typeof LinkLegacy) =>
22
+ t.exact(
23
+ t.intersection([
24
+ t.partial({
25
+ data: linkCodec,
26
+ }),
27
+ t.type({
28
+ start: t.number,
29
+ end: t.number,
30
+ type: t.union([RichTextNodeTypeCodec, t.literal("label")]),
31
+ }),
32
+ ]),
33
+ )
34
+
35
+ export const Span = SpanFn(Link)
36
+ export type Span = t.TypeOf<typeof Span>
37
+
38
+ export const SpanLegacy = SpanFn(LinkLegacy)
39
+ export type SpanLegacy = t.TypeOf<typeof SpanLegacy>
40
+
41
+ export const ValidatedSpans = <C extends typeof Span | typeof SpanLegacy>(
42
+ spanCodec: C,
43
+ ) => {
44
+ type S = t.TypeOf<C>
45
+
46
+ return new t.Type<S[], S[], unknown>(
47
+ "ValidatedSpans",
48
+ (spans): spans is S[] => Array.isArray(spans) && spans.every(spanCodec.is),
49
+ (spans: unknown, c) => {
50
+ if (Array.isArray(spans)) {
51
+ const res = spans
52
+ .reduce<Array<S>>((acc, maybeSpan) => {
53
+ const decodedSpan = spanCodec.decode(maybeSpan)
54
+ return isRight(decodedSpan) ? [...acc, decodedSpan.right] : acc
61
55
  }, [])
62
- .sort((m1: Meta, m2: Meta) => m1.start - m2.start)
56
+ .sort((m1: S, m2: S) => m1.start - m2.start)
63
57
  return t.success(res)
64
- } else return t.failure(metas, c)
58
+ } else return t.failure(spans, c)
65
59
  },
66
60
  (m) => {
67
- return m.reduce<Array<Meta>>((acc, meta) => {
68
- if (meta.type === "hyperlink" && meta.data) {
69
- // since the Span data are typed as unknown we have to redecode for type safety and then encode to either new format or legacy.
70
- const decoded = linkCodec.decode(meta.data)
71
- if (isLeft(decoded)) return acc
72
-
73
- return [...acc, { ...meta, data: linkCodec.encode(decoded.right) }]
74
- }
75
- return [...acc, Meta.encode(meta)]
61
+ return m.reduce<Array<S>>((acc, meta) => {
62
+ return [...acc, spanCodec.encode(meta)]
76
63
  }, [])
77
64
  },
78
65
  )
66
+ }
79
67
 
80
- const ImageBlockCodec = (linkCodec: LinkCodec) =>
68
+ const ImageBlockCodec = (linkCodec: typeof Link | typeof LinkLegacy) =>
81
69
  t.exact(
82
70
  t.intersection([
83
71
  t.type({
@@ -169,8 +157,9 @@ export function checkEmbedBlock(block: Block): block is EmbedBlock {
169
157
  return block.type === RichTextNodeType.embed
170
158
  }
171
159
 
172
- type LinkCodec = typeof Link | typeof LinkLegacy
173
- const TextBlockCodec = (linkCodec: LinkCodec) =>
160
+ const TextBlockCodec = <C extends typeof Span | typeof SpanLegacy>(
161
+ spanCodec: C,
162
+ ) =>
174
163
  t.exact(
175
164
  t.intersection([
176
165
  t.type({
@@ -184,7 +173,7 @@ const TextBlockCodec = (linkCodec: LinkCodec) =>
184
173
  text: t.string,
185
174
  }),
186
175
  t.partial({
187
- spans: ValidatedMetas(linkCodec),
176
+ spans: ValidatedSpans(spanCodec),
188
177
  }),
189
178
  ]),
190
179
  }),
@@ -195,10 +184,11 @@ const TextBlockCodec = (linkCodec: LinkCodec) =>
195
184
  ]),
196
185
  )
197
186
 
198
- export const TextBlock = TextBlockCodec(Link)
187
+ /* These Text block will decode codec A and encode from codec B to A */
188
+ export const TextBlock = TextBlockCodec(Span)
199
189
  export type TextBlock = t.TypeOf<typeof TextBlock>
200
190
 
201
- export const TextBlockLegacy = TextBlockCodec(LinkLegacy)
191
+ const TextBlockLegacy = TextBlockCodec(SpanLegacy)
202
192
  type TextBlockLegacy = t.TypeOf<typeof TextBlockLegacy>
203
193
 
204
194
  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
8
  export function convertImageView<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
  {
@@ -1,14 +1,17 @@
1
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";
2
+ import type { EmbedBlock } from "../../../../../content"
3
+ import type { ImportEmbedBlock } from "../../../../validators/fields/nestable/ImportRichText/blocks"
4
+ import { embedConverter } from "../Embed"
5
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
- }
6
+ export function embedBlockConverter(
7
+ block: ImportEmbedBlock,
8
+ embeds: Record<string, Embed | undefined>,
9
+ ): EmbedBlock {
10
+ const embedData = embedConverter(block.oembed, embeds)
11
+
12
+ if (!embedData) throw new Error("Failed to convert embed data")
13
+ return {
14
+ type: block.type,
15
+ data: embedData,
16
+ }
14
17
  }
@@ -1,14 +1,17 @@
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";
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
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
- }
6
+ export function imageBlockConverter(
7
+ block: ImportImageBlock,
8
+ assets: Record<Asset["id"], Asset | undefined>,
9
+ ): ImageBlock {
10
+ return {
11
+ type: block.type,
12
+ data: convertImageView<ImportImageBlock>(
13
+ block,
14
+ getAssetOrThrow(assets)(block.id),
15
+ ),
16
+ }
14
17
  }
@@ -15,9 +15,9 @@ export const richTextConverter = (
15
15
  return {
16
16
  __TYPE__: RichTextContentType,
17
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
- }),
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
22
  }
23
23
  }
@@ -3,33 +3,46 @@ import type { TextBlock } from "../../../../../content"
3
3
  import type { ImportTextBlock } from "../../../../validators/fields/nestable/ImportRichText/blocks"
4
4
  import { linkConverter } from "../Link"
5
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
- }
6
+ export function textBlockConverter(
7
+ block: ImportTextBlock,
8
+ assets: Record<Asset["id"], Asset | undefined>,
9
+ ): TextBlock {
10
+ return {
11
+ type: block.type,
12
+ content: {
13
+ text: block.text,
14
+ ...(() => {
15
+ if (block.spans) {
16
+ const convertedSpans = spansConverter(block.spans, assets)
17
+ if (!convertedSpans) return {}
18
+
19
+ return { spans: convertedSpans }
20
+ }
21
+ return {}
22
+ })(),
23
+ },
24
+ ...(block.direction ? { direction: block.direction } : {}),
25
+ }
15
26
  }
16
27
 
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
+ function spansConverter(
29
+ spans: NonNullable<ImportTextBlock["spans"]>,
30
+ assets: Record<Asset["id"], Asset | undefined>,
31
+ ): TextBlock["content"]["spans"] {
32
+ return spans.map((span) => {
33
+ return {
34
+ type: span.type,
35
+ start: span.start,
36
+ end: span.end,
37
+ ...(() => {
38
+ if (span.type === "hyperlink") {
39
+ const convertedLinkContent = linkConverter(span.data, assets)
40
+ if (!convertedLinkContent) return {}
28
41
 
29
- return {
30
- type: span.type,
31
- start: span.start,
32
- end: span.end
33
- }
34
- })
42
+ return { data: convertedLinkContent?.value }
43
+ }
44
+ return {}
45
+ })(),
46
+ }
47
+ })
35
48
  }
@@ -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 { 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,55 +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 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;