@prismicio/types-internal 2.2.0-traverse.alpha-9 → 2.2.0-traverse.alpha-11

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 (32) hide show
  1. package/lib/content/Document.d.ts +384 -192
  2. package/lib/content/fields/GroupContent.d.ts +84 -42
  3. package/lib/content/fields/WidgetContent.d.ts +384 -192
  4. package/lib/content/fields/nestable/NestableContent.d.ts +48 -24
  5. package/lib/content/fields/nestable/RichTextContent/Blocks.d.ts +117 -105
  6. package/lib/content/fields/nestable/RichTextContent/Blocks.js +23 -18
  7. package/lib/content/fields/nestable/RichTextContent/index.d.ts +60 -30
  8. package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +96 -48
  9. package/lib/content/fields/slices/Slice/RepeatableContent.d.ts +36 -18
  10. package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +96 -48
  11. package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +96 -48
  12. package/lib/content/fields/slices/Slice/index.d.ts +216 -108
  13. package/lib/content/fields/slices/SliceItem.d.ts +216 -108
  14. package/lib/content/fields/slices/SlicesContent.d.ts +288 -144
  15. package/lib/import/converters/fields/nestable/RichText/textBlock.js +29 -16
  16. package/lib/import/validators/fields/nestable/ImportRichText/blocks/ImportTextBlock.d.ts +9 -1
  17. package/lib/import/validators/fields/nestable/ImportRichText/blocks/Span.d.ts +18 -4
  18. package/lib/import/validators/fields/nestable/ImportRichText/blocks/Span.js +9 -2
  19. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/LabelSpan.d.ts +12 -0
  20. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/LabelSpan.js +16 -0
  21. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.d.ts +0 -2
  22. package/lib/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.js +0 -2
  23. package/package.json +1 -1
  24. package/src/content/fields/nestable/RichTextContent/Blocks.ts +26 -25
  25. package/src/import/converters/fields/nestable/RichText/textBlock.ts +30 -16
  26. package/src/import/validators/fields/nestable/ImportRichText/blocks/Span.ts +9 -5
  27. package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/LabelSpan.ts +19 -0
  28. package/src/import/validators/fields/nestable/ImportRichText/blocks/spans/TextSpan.ts +0 -2
  29. package/lib/import/converters/fields/nestable/GeooPoint.d.ts +0 -3
  30. package/lib/import/converters/fields/nestable/GeooPoint.js +0 -15
  31. package/lib/import/converters/fields/nestable/RichText.d.ts +0 -4
  32. package/lib/import/converters/fields/nestable/RichText.js +0 -55
@@ -22,20 +22,33 @@ function textBlockConverter(block, assets) {
22
22
  }
23
23
  exports.textBlockConverter = textBlockConverter;
24
24
  function spansConverter(spans, assets) {
25
- return spans.map((span) => {
26
- return {
27
- type: span.type,
28
- start: span.start,
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
- })(),
39
- };
40
- });
25
+ return spans.reduce((acc, span) => {
26
+ switch (span.type) {
27
+ case "em":
28
+ case "strong":
29
+ return [...acc, span];
30
+ case "label":
31
+ return [
32
+ ...acc,
33
+ {
34
+ ...span,
35
+ data: span.data.label,
36
+ },
37
+ ];
38
+ case "hyperlink": {
39
+ const convertedLink = (0, Link_1.linkConverter)(span.data, assets);
40
+ if (!convertedLink)
41
+ return acc;
42
+ return [
43
+ ...acc,
44
+ {
45
+ type: span.type,
46
+ start: span.start,
47
+ end: span.end,
48
+ data: convertedLink.value,
49
+ },
50
+ ];
51
+ }
52
+ }
53
+ }, []);
41
54
  }
@@ -58,7 +58,15 @@ export declare const ImportTextBlock: t.ExactC<t.IntersectionC<[t.TypeC<{
58
58
  id: string;
59
59
  };
60
60
  }) | ({
61
- type: "label" | "strong" | "em";
61
+ type: "strong" | "em";
62
+ } & {
63
+ start: number;
64
+ end: number;
65
+ }) | ({
66
+ type: "label";
67
+ data: {
68
+ label: string;
69
+ };
62
70
  } & {
63
71
  start: number;
64
72
  end: number;
@@ -2,8 +2,7 @@ import * as t from "io-ts";
2
2
  declare const SpanType: t.UnionC<[t.LiteralC<"hyperlink">, t.KeyofC<{
3
3
  strong: null;
4
4
  em: null;
5
- label: null;
6
- }>]>;
5
+ }>, t.LiteralC<"label">]>;
7
6
  export declare type SpanType = t.TypeOf<typeof SpanType>;
8
7
  declare const SpanShape: t.UnionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
9
8
  type: t.LiteralC<"hyperlink">;
@@ -29,11 +28,18 @@ declare const SpanShape: t.UnionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
29
28
  type: t.KeyofC<{
30
29
  strong: null;
31
30
  em: null;
32
- label: null;
33
31
  }>;
34
32
  }>, t.TypeC<{
35
33
  start: t.NumberC;
36
34
  end: t.NumberC;
35
+ }>]>>, t.ExactC<t.IntersectionC<[t.TypeC<{
36
+ type: t.LiteralC<"label">;
37
+ data: t.ExactC<t.TypeC<{
38
+ label: t.StringC;
39
+ }>>;
40
+ }>, t.TypeC<{
41
+ start: t.NumberC;
42
+ end: t.NumberC;
37
43
  }>]>>]>;
38
44
  export declare type Span = t.TypeOf<typeof SpanShape>;
39
45
  export declare const Span: t.Type<({
@@ -55,7 +61,15 @@ export declare const Span: t.Type<({
55
61
  id: string;
56
62
  };
57
63
  }) | ({
58
- type: "label" | "strong" | "em";
64
+ type: "strong" | "em";
65
+ } & {
66
+ start: number;
67
+ end: number;
68
+ }) | ({
69
+ type: "label";
70
+ data: {
71
+ label: string;
72
+ };
59
73
  } & {
60
74
  start: number;
61
75
  end: number;
@@ -5,15 +5,22 @@ const tslib_1 = require("tslib");
5
5
  const t = (0, tslib_1.__importStar)(require("io-ts"));
6
6
  const function_1 = require("../../../../../../validators/function");
7
7
  const spans_1 = require("./spans");
8
- const SpanType = (0, function_1.withCustomError)(t.union([spans_1.HyperlinkSpanType, spans_1.TextSpanType]), () => `Span 'type' field must be specified and have one of the following values: ${Object.keys(spans_1.TextSpanType.keys).join(", ")} or ${spans_1.HyperlinkSpanType.value}`);
8
+ const LabelSpan_1 = require("./spans/LabelSpan");
9
+ const SpanType = (0, function_1.withCustomError)(t.union([spans_1.HyperlinkSpanType, spans_1.TextSpanType, LabelSpan_1.LabelSpanType]), () => `Span 'type' field must be specified and have one of the following values: ${[
10
+ ...Object.keys(spans_1.TextSpanType.keys),
11
+ LabelSpan_1.LabelSpanType.value,
12
+ ].join(", ")} or ${spans_1.HyperlinkSpanType.value}`);
9
13
  const SpanTypeValidator = (0, function_1.withCustomError)(t.type({
10
14
  type: SpanType,
11
15
  }), () => "Span must be an object");
12
- const SpanShape = t.union([spans_1.HyperlinkSpan, spans_1.TextSpan]);
16
+ const SpanShape = t.union([spans_1.HyperlinkSpan, spans_1.TextSpan, LabelSpan_1.LabelSpan]);
13
17
  exports.Span = SpanTypeValidator.pipe(new t.Type("Span", (u) => SpanShape.is(u), (u, c) => {
14
18
  if (spans_1.HyperlinkSpanType.is(u.type)) {
15
19
  return spans_1.HyperlinkSpan.validate(u, c);
16
20
  }
21
+ else if (LabelSpan_1.LabelSpanType.is(u.type)) {
22
+ return LabelSpan_1.LabelSpan.validate(u, c);
23
+ }
17
24
  else {
18
25
  return spans_1.TextSpan.validate(u, c);
19
26
  }
@@ -0,0 +1,12 @@
1
+ import * as t from "io-ts";
2
+ export declare const LabelSpanType: t.LiteralC<"label">;
3
+ export declare const LabelSpan: t.ExactC<t.IntersectionC<[t.TypeC<{
4
+ type: t.LiteralC<"label">;
5
+ data: t.ExactC<t.TypeC<{
6
+ label: t.StringC;
7
+ }>>;
8
+ }>, t.TypeC<{
9
+ start: t.NumberC;
10
+ end: t.NumberC;
11
+ }>]>>;
12
+ export declare type LabelSpan = t.TypeOf<typeof LabelSpan>;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LabelSpan = exports.LabelSpanType = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const t = (0, tslib_1.__importStar)(require("io-ts"));
6
+ const SpanLocation_1 = require("./SpanLocation");
7
+ exports.LabelSpanType = t.literal("label");
8
+ exports.LabelSpan = t.exact(t.intersection([
9
+ t.type({
10
+ type: exports.LabelSpanType,
11
+ data: t.strict({
12
+ label: t.string,
13
+ }),
14
+ }),
15
+ SpanLocation_1.SpanLocation,
16
+ ]));
@@ -2,13 +2,11 @@ import * as t from "io-ts";
2
2
  export declare const TextSpanType: t.KeyofC<{
3
3
  strong: null;
4
4
  em: null;
5
- label: null;
6
5
  }>;
7
6
  export declare const TextSpan: t.ExactC<t.IntersectionC<[t.TypeC<{
8
7
  type: t.KeyofC<{
9
8
  strong: null;
10
9
  em: null;
11
- label: null;
12
10
  }>;
13
11
  }>, t.TypeC<{
14
12
  start: t.NumberC;
@@ -7,12 +7,10 @@ const SpanLocation_1 = require("./SpanLocation");
7
7
  const TextSpanTypes = {
8
8
  Strong: "strong",
9
9
  Em: "em",
10
- Label: "label",
11
10
  };
12
11
  exports.TextSpanType = t.keyof({
13
12
  [TextSpanTypes.Strong]: null,
14
13
  [TextSpanTypes.Em]: null,
15
- [TextSpanTypes.Label]: null,
16
14
  });
17
15
  exports.TextSpan = t.exact(t.intersection([
18
16
  t.type({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/types-internal",
3
- "version": "2.2.0-traverse.alpha-9",
3
+ "version": "2.2.0-traverse.alpha-11",
4
4
  "description": "Prismic types for Custom Types and Prismic Data",
5
5
  "keywords": [
6
6
  "typescript",
@@ -2,6 +2,7 @@ import { either } from "fp-ts"
2
2
  import { isLeft } from "fp-ts/lib/Either"
3
3
  import { pipe } from "fp-ts/lib/function"
4
4
  import * as t from "io-ts"
5
+ import { withFallback } from "io-ts-types"
5
6
 
6
7
  import {
7
8
  RichTextNodeType,
@@ -18,28 +19,34 @@ import {
18
19
  import { ImageContentView } from "../ImageContent"
19
20
  import { Link, LinkLegacy } from "../LinkContent"
20
21
 
21
- const labelCodec = t.strict({
22
- label: t.string,
22
+ const linkSpan = (linkCodec: typeof Link | typeof LinkLegacy) =>
23
+ t.strict({
24
+ data: linkCodec,
25
+ start: t.number,
26
+ end: t.number,
27
+ type: t.literal(RichTextNodeType.hyperlink),
28
+ })
29
+
30
+ const labelSpan = t.strict({
31
+ data: withFallback(t.string, ""),
32
+ start: t.number,
33
+ end: t.number,
34
+ type: t.literal("label"),
23
35
  })
24
36
 
25
- const SpanFn = (linkCodec: typeof Link | typeof LinkLegacy) =>
26
- t.exact(
27
- t.intersection([
28
- t.partial({
29
- data: t.union([linkCodec, labelCodec]),
30
- }),
31
- t.type({
32
- start: t.number,
33
- end: t.number,
34
- type: t.union([RichTextNodeTypeCodec, t.literal("label")]),
35
- }),
36
- ]),
37
- )
37
+ const basicSpan = t.strict({
38
+ start: t.number,
39
+ end: t.number,
40
+ type: t.keyof({
41
+ [RichTextNodeType.strong]: null,
42
+ [RichTextNodeType.em]: null,
43
+ }),
44
+ })
38
45
 
39
- export const Span = SpanFn(Link)
46
+ export const Span = t.union([linkSpan(Link), labelSpan, basicSpan])
40
47
  export type Span = t.TypeOf<typeof Span>
41
48
 
42
- export const SpanLegacy = SpanFn(LinkLegacy)
49
+ export const SpanLegacy = t.union([linkSpan(LinkLegacy), labelSpan, basicSpan])
43
50
  export type SpanLegacy = t.TypeOf<typeof SpanLegacy>
44
51
 
45
52
  export const ValidatedSpans = <C extends typeof Span | typeof SpanLegacy>(
@@ -56,13 +63,6 @@ export const ValidatedSpans = <C extends typeof Span | typeof SpanLegacy>(
56
63
  .reduce<Array<S>>((acc, maybeSpan) => {
57
64
  const decodedSpan = spanCodec.decode(maybeSpan)
58
65
  if (isLeft(decodedSpan)) return acc
59
- if (
60
- (decodedSpan.right.type === "hyperlink" ||
61
- decodedSpan.right.type === "label") &&
62
- !decodedSpan.right.data
63
- )
64
- return acc
65
-
66
66
  return [...acc, decodedSpan.right]
67
67
  }, [])
68
68
  .sort((m1: S, m2: S) => m1.start - m2.start)
@@ -71,7 +71,8 @@ export const ValidatedSpans = <C extends typeof Span | typeof SpanLegacy>(
71
71
  },
72
72
  (m) => {
73
73
  return m.reduce<Array<S>>((acc, meta) => {
74
- return [...acc, spanCodec.encode(meta)]
74
+ const encoded = <S>spanCodec.encode(meta)
75
+ return [...acc, encoded]
75
76
  }, [])
76
77
  },
77
78
  )
@@ -1,5 +1,5 @@
1
1
  import type { Asset } from "../../../../../common"
2
- import type { TextBlock } from "../../../../../content"
2
+ import type { Span, TextBlock } from "../../../../../content"
3
3
  import type { ImportTextBlock } from "../../../../validators/fields/nestable/ImportRichText/blocks"
4
4
  import { linkConverter } from "../Link"
5
5
 
@@ -28,21 +28,35 @@ export function textBlockConverter(
28
28
  function spansConverter(
29
29
  spans: NonNullable<ImportTextBlock["spans"]>,
30
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 {}
31
+ ): Span[] {
32
+ return spans.reduce<Span[]>((acc, span) => {
33
+ switch (span.type) {
34
+ case "em":
35
+ case "strong":
36
+ return [...acc, span]
37
+ case "label":
38
+ return [
39
+ ...acc,
40
+ {
41
+ ...span,
42
+ data: span.data.label,
43
+ },
44
+ ]
41
45
 
42
- return { data: convertedLinkContent?.value }
43
- }
44
- return {}
45
- })(),
46
+ case "hyperlink": {
47
+ const convertedLink = linkConverter(span.data, assets)
48
+ if (!convertedLink) return acc
49
+
50
+ return [
51
+ ...acc,
52
+ {
53
+ type: span.type,
54
+ start: span.start,
55
+ end: span.end,
56
+ data: convertedLink.value,
57
+ },
58
+ ]
59
+ }
46
60
  }
47
- })
61
+ }, [])
48
62
  }
@@ -7,13 +7,15 @@ import {
7
7
  TextSpan,
8
8
  TextSpanType,
9
9
  } from "./spans"
10
+ import { LabelSpan, LabelSpanType } from "./spans/LabelSpan"
10
11
 
11
12
  const SpanType = withCustomError(
12
- t.union([HyperlinkSpanType, TextSpanType]),
13
+ t.union([HyperlinkSpanType, TextSpanType, LabelSpanType]),
13
14
  () =>
14
- `Span 'type' field must be specified and have one of the following values: ${Object.keys(
15
- TextSpanType.keys,
16
- ).join(", ")} or ${HyperlinkSpanType.value}`,
15
+ `Span 'type' field must be specified and have one of the following values: ${[
16
+ ...Object.keys(TextSpanType.keys),
17
+ LabelSpanType.value,
18
+ ].join(", ")} or ${HyperlinkSpanType.value}`,
17
19
  )
18
20
  export type SpanType = t.TypeOf<typeof SpanType>
19
21
 
@@ -24,7 +26,7 @@ const SpanTypeValidator = withCustomError(
24
26
  () => "Span must be an object",
25
27
  )
26
28
 
27
- const SpanShape = t.union([HyperlinkSpan, TextSpan])
29
+ const SpanShape = t.union([HyperlinkSpan, TextSpan, LabelSpan])
28
30
 
29
31
  export type Span = t.TypeOf<typeof SpanShape>
30
32
 
@@ -35,6 +37,8 @@ export const Span = SpanTypeValidator.pipe(
35
37
  (u, c) => {
36
38
  if (HyperlinkSpanType.is(u.type)) {
37
39
  return HyperlinkSpan.validate(u, c)
40
+ } else if (LabelSpanType.is(u.type)) {
41
+ return LabelSpan.validate(u, c)
38
42
  } else {
39
43
  return TextSpan.validate(u, c)
40
44
  }
@@ -0,0 +1,19 @@
1
+ import * as t from "io-ts"
2
+
3
+ import { SpanLocation } from "./SpanLocation"
4
+
5
+ export const LabelSpanType = t.literal("label")
6
+
7
+ export const LabelSpan = t.exact(
8
+ t.intersection([
9
+ t.type({
10
+ type: LabelSpanType,
11
+ data: t.strict({
12
+ label: t.string,
13
+ }),
14
+ }),
15
+ SpanLocation,
16
+ ]),
17
+ )
18
+
19
+ export type LabelSpan = t.TypeOf<typeof LabelSpan>
@@ -5,13 +5,11 @@ import { SpanLocation } from "./SpanLocation"
5
5
  const TextSpanTypes = {
6
6
  Strong: "strong",
7
7
  Em: "em",
8
- Label: "label",
9
8
  } as const
10
9
 
11
10
  export const TextSpanType = t.keyof({
12
11
  [TextSpanTypes.Strong]: null,
13
12
  [TextSpanTypes.Em]: null,
14
- [TextSpanTypes.Label]: null,
15
13
  })
16
14
 
17
15
  export const TextSpan = t.exact(
@@ -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;