@prismicio/types-internal 2.2.0-traverse.alpha-10 → 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 (28) hide show
  1. package/lib/content/Document.d.ts +32 -32
  2. package/lib/content/fields/GroupContent.d.ts +7 -7
  3. package/lib/content/fields/WidgetContent.d.ts +32 -32
  4. package/lib/content/fields/nestable/NestableContent.d.ts +4 -4
  5. package/lib/content/fields/nestable/RichTextContent/Blocks.d.ts +18 -9
  6. package/lib/content/fields/nestable/RichTextContent/Blocks.js +9 -9
  7. package/lib/content/fields/nestable/RichTextContent/index.d.ts +5 -5
  8. package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +8 -8
  9. package/lib/content/fields/slices/Slice/RepeatableContent.d.ts +3 -3
  10. package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +8 -8
  11. package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +8 -8
  12. package/lib/content/fields/slices/Slice/index.d.ts +18 -18
  13. package/lib/content/fields/slices/SliceItem.d.ts +18 -18
  14. package/lib/content/fields/slices/SlicesContent.d.ts +24 -24
  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 +9 -13
  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
@@ -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(