@prismicio/types-internal 2.0.0-beta.0 → 2.0.0-beta.1

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 (165) hide show
  1. package/lib/common/WidgetKey.d.ts +1 -1
  2. package/lib/common/WidgetKey.js +1 -1
  3. package/lib/common/index.js +1 -1
  4. package/lib/content/Document.d.ts +20 -100
  5. package/lib/content/Document.js +1 -1
  6. package/lib/content/LegacyContentCtx.d.ts +2 -2
  7. package/lib/content/LegacyContentCtx.js +1 -1
  8. package/lib/content/fields/EmptyContent.d.ts +1 -1
  9. package/lib/content/fields/EmptyContent.js +1 -1
  10. package/lib/content/fields/GroupContent.d.ts +8 -28
  11. package/lib/content/fields/GroupContent.js +1 -1
  12. package/lib/content/fields/UIDContent.d.ts +1 -1
  13. package/lib/content/fields/UIDContent.js +1 -1
  14. package/lib/content/fields/WidgetContent.d.ts +18 -98
  15. package/lib/content/fields/WidgetContent.js +1 -1
  16. package/lib/content/fields/index.js +6 -6
  17. package/lib/content/fields/nestable/BooleanContent.d.ts +1 -1
  18. package/lib/content/fields/nestable/BooleanContent.js +1 -1
  19. package/lib/content/fields/nestable/EmbedContent.d.ts +2 -2
  20. package/lib/content/fields/nestable/EmbedContent.js +1 -1
  21. package/lib/content/fields/nestable/FieldContent/ColorContent.d.ts +1 -1
  22. package/lib/content/fields/nestable/FieldContent/ColorContent.js +2 -2
  23. package/lib/content/fields/nestable/FieldContent/DateContent.d.ts +1 -1
  24. package/lib/content/fields/nestable/FieldContent/DateContent.js +2 -2
  25. package/lib/content/fields/nestable/FieldContent/NumberContent.d.ts +1 -1
  26. package/lib/content/fields/nestable/FieldContent/NumberContent.js +2 -2
  27. package/lib/content/fields/nestable/FieldContent/RangeContent.d.ts +1 -1
  28. package/lib/content/fields/nestable/FieldContent/RangeContent.js +2 -2
  29. package/lib/content/fields/nestable/FieldContent/SelectContent.d.ts +1 -1
  30. package/lib/content/fields/nestable/FieldContent/SelectContent.js +2 -2
  31. package/lib/content/fields/nestable/FieldContent/TextContent.d.ts +1 -1
  32. package/lib/content/fields/nestable/FieldContent/TextContent.js +2 -2
  33. package/lib/content/fields/nestable/FieldContent/TimestampContent.d.ts +1 -1
  34. package/lib/content/fields/nestable/FieldContent/TimestampContent.js +2 -2
  35. package/lib/content/fields/nestable/FieldContent/index.d.ts +2 -2
  36. package/lib/content/fields/nestable/FieldContent/index.js +9 -9
  37. package/lib/content/fields/nestable/GeoPointContent.d.ts +1 -1
  38. package/lib/content/fields/nestable/GeoPointContent.js +1 -1
  39. package/lib/content/fields/nestable/ImageContent.d.ts +2 -2
  40. package/lib/content/fields/nestable/ImageContent.js +1 -1
  41. package/lib/content/fields/nestable/IntegrationFieldContent.d.ts +1 -1
  42. package/lib/content/fields/nestable/IntegrationFieldContent.js +1 -1
  43. package/lib/content/fields/nestable/LinkContent.d.ts +6 -6
  44. package/lib/content/fields/nestable/LinkContent.js +1 -1
  45. package/lib/content/fields/nestable/NestableContent.d.ts +4 -14
  46. package/lib/content/fields/nestable/NestableContent.js +1 -1
  47. package/lib/content/fields/nestable/RichTextContent/Blocks.d.ts +11 -31
  48. package/lib/content/fields/nestable/RichTextContent/Blocks.js +15 -11
  49. package/lib/content/fields/nestable/RichTextContent/index.d.ts +3 -13
  50. package/lib/content/fields/nestable/RichTextContent/index.js +3 -3
  51. package/lib/content/fields/nestable/SeparatorContent.d.ts +1 -1
  52. package/lib/content/fields/nestable/SeparatorContent.js +1 -1
  53. package/lib/content/fields/nestable/index.js +10 -10
  54. package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +5 -25
  55. package/lib/content/fields/slices/Slice/CompositeSliceContent.js +1 -1
  56. package/lib/content/fields/slices/Slice/RepeatableContent.d.ts +2 -12
  57. package/lib/content/fields/slices/Slice/RepeatableContent.js +1 -1
  58. package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +5 -25
  59. package/lib/content/fields/slices/Slice/SharedSliceContent.js +1 -1
  60. package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +279 -27
  61. package/lib/content/fields/slices/Slice/SimpleSliceContent.js +6 -2
  62. package/lib/content/fields/slices/Slice/index.d.ts +285 -73
  63. package/lib/content/fields/slices/Slice/index.js +4 -4
  64. package/lib/content/fields/slices/SliceItem.d.ts +13 -73
  65. package/lib/content/fields/slices/SliceItem.js +1 -1
  66. package/lib/content/fields/slices/SlicesContent.d.ts +14 -74
  67. package/lib/content/fields/slices/SlicesContent.js +1 -1
  68. package/lib/content/fields/slices/index.js +3 -3
  69. package/lib/content/index.js +3 -3
  70. package/lib/content/utils.d.ts +2 -2
  71. package/lib/content/utils.js +2 -1
  72. package/lib/customtypes/CustomType.d.ts +14 -2
  73. package/lib/customtypes/CustomType.js +7 -2
  74. package/lib/customtypes/Section.d.ts +2 -2
  75. package/lib/customtypes/Section.js +1 -1
  76. package/lib/customtypes/diff/Changes.d.ts +4 -4
  77. package/lib/customtypes/diff/SharedSlice.d.ts +671 -3
  78. package/lib/customtypes/diff/Variation.d.ts +657 -3
  79. package/lib/customtypes/diff/index.js +3 -3
  80. package/lib/customtypes/index.js +4 -4
  81. package/lib/customtypes/widgets/Group.d.ts +2 -2
  82. package/lib/customtypes/widgets/Group.js +1 -1
  83. package/lib/customtypes/widgets/UID.d.ts +2 -2
  84. package/lib/customtypes/widgets/UID.js +1 -1
  85. package/lib/customtypes/widgets/Widget.d.ts +3 -3
  86. package/lib/customtypes/widgets/Widget.js +1 -1
  87. package/lib/customtypes/widgets/index.js +6 -6
  88. package/lib/customtypes/widgets/nestable/BooleanField.d.ts +2 -2
  89. package/lib/customtypes/widgets/nestable/BooleanField.js +1 -1
  90. package/lib/customtypes/widgets/nestable/Color.d.ts +2 -2
  91. package/lib/customtypes/widgets/nestable/Color.js +1 -1
  92. package/lib/customtypes/widgets/nestable/Date.d.ts +2 -2
  93. package/lib/customtypes/widgets/nestable/Date.js +1 -1
  94. package/lib/customtypes/widgets/nestable/Embed.d.ts +2 -2
  95. package/lib/customtypes/widgets/nestable/Embed.js +1 -1
  96. package/lib/customtypes/widgets/nestable/GeoPoint.d.ts +2 -2
  97. package/lib/customtypes/widgets/nestable/GeoPoint.js +1 -1
  98. package/lib/customtypes/widgets/nestable/Image.d.ts +3 -3
  99. package/lib/customtypes/widgets/nestable/Image.js +2 -2
  100. package/lib/customtypes/widgets/nestable/IntegrationField.d.ts +2 -2
  101. package/lib/customtypes/widgets/nestable/IntegrationField.js +1 -1
  102. package/lib/customtypes/widgets/nestable/Link/ContentRelationshipResolver.d.ts +29 -0
  103. package/lib/customtypes/widgets/nestable/Link/ContentRelationshipResolver.js +44 -0
  104. package/lib/customtypes/widgets/nestable/Link/index.d.ts +82 -0
  105. package/lib/customtypes/widgets/nestable/Link/index.js +56 -0
  106. package/lib/customtypes/widgets/nestable/Link.d.ts +2 -2
  107. package/lib/customtypes/widgets/nestable/Link.js +1 -1
  108. package/lib/customtypes/widgets/nestable/NestableWidget.d.ts +2 -2
  109. package/lib/customtypes/widgets/nestable/NestableWidget.js +1 -1
  110. package/lib/customtypes/widgets/nestable/Number.d.ts +2 -2
  111. package/lib/customtypes/widgets/nestable/Number.js +1 -1
  112. package/lib/customtypes/widgets/nestable/Range.d.ts +2 -2
  113. package/lib/customtypes/widgets/nestable/Range.js +1 -1
  114. package/lib/customtypes/widgets/nestable/RichText.d.ts +3 -3
  115. package/lib/customtypes/widgets/nestable/RichText.js +2 -2
  116. package/lib/customtypes/widgets/nestable/Select.d.ts +2 -2
  117. package/lib/customtypes/widgets/nestable/Select.js +1 -1
  118. package/lib/customtypes/widgets/nestable/Separator.d.ts +2 -2
  119. package/lib/customtypes/widgets/nestable/Separator.js +1 -1
  120. package/lib/customtypes/widgets/nestable/Text.d.ts +2 -2
  121. package/lib/customtypes/widgets/nestable/Text.js +1 -1
  122. package/lib/customtypes/widgets/nestable/Timestamp.d.ts +2 -2
  123. package/lib/customtypes/widgets/nestable/Timestamp.js +1 -1
  124. package/lib/customtypes/widgets/nestable/index.js +16 -16
  125. package/lib/customtypes/widgets/shared/ImageConstraint.d.ts +1 -1
  126. package/lib/customtypes/widgets/shared/ImageConstraint.js +1 -1
  127. package/lib/customtypes/widgets/slices/CompositeSlice.d.ts +2 -2
  128. package/lib/customtypes/widgets/slices/CompositeSlice.js +1 -1
  129. package/lib/customtypes/widgets/slices/LegacySlice.d.ts +1 -1
  130. package/lib/customtypes/widgets/slices/LegacySlice.js +1 -1
  131. package/lib/customtypes/widgets/slices/SharedSlice.d.ts +2 -2
  132. package/lib/customtypes/widgets/slices/SharedSlice.js +1 -1
  133. package/lib/customtypes/widgets/slices/SharedSliceRef.d.ts +1 -1
  134. package/lib/customtypes/widgets/slices/SharedSliceRef.js +1 -1
  135. package/lib/customtypes/widgets/slices/Slice.d.ts +2 -2
  136. package/lib/customtypes/widgets/slices/Slices.d.ts +5 -5
  137. package/lib/customtypes/widgets/slices/Slices.js +1 -1
  138. package/lib/customtypes/widgets/slices/SlicesTypes.d.ts +1 -1
  139. package/lib/customtypes/widgets/slices/SlicesTypes.js +1 -1
  140. package/lib/customtypes/widgets/slices/index.js +7 -7
  141. package/lib/utils/index.js +2 -2
  142. package/lib/validators/DateFromString.js +1 -1
  143. package/lib/validators/DateFromStringOrNumber.js +1 -1
  144. package/lib/validators/DateFromTsMs.js +1 -1
  145. package/lib/validators/IntFromNumber.d.ts +2 -2
  146. package/lib/validators/IntFromNumber.js +1 -1
  147. package/lib/validators/IntFromPixels.d.ts +2 -2
  148. package/lib/validators/IntFromPixels.js +1 -1
  149. package/lib/validators/NonEmptyString.js +1 -1
  150. package/lib/validators/NonEmptyStringOrNull.js +1 -1
  151. package/lib/validators/NumberOrNull.js +1 -1
  152. package/lib/validators/StringFromBoolean.d.ts +2 -2
  153. package/lib/validators/StringFromBoolean.js +1 -1
  154. package/lib/validators/StringFromNumber.d.ts +2 -2
  155. package/lib/validators/StringFromNumber.js +1 -1
  156. package/lib/validators/StringOrNull.js +1 -1
  157. package/lib/validators/TrimmedString.d.ts +2 -2
  158. package/lib/validators/TrimmedString.js +1 -1
  159. package/lib/validators/function.js +1 -1
  160. package/lib/validators/index.js +12 -12
  161. package/package.json +1 -1
  162. package/src/content/fields/nestable/RichTextContent/Blocks.ts +31 -23
  163. package/src/content/fields/nestable/RichTextContent/index.ts +1 -3
  164. package/src/content/fields/slices/Slice/SimpleSliceContent.ts +4 -1
  165. package/src/customtypes/CustomType.ts +6 -0
@@ -77,24 +77,31 @@ export const ValidatedMetas = (linkCodec: LinkCodec) =>
77
77
  },
78
78
  )
79
79
 
80
- export const ImageBlock = t.exact(
81
- t.intersection([
82
- t.type({
83
- type: t.literal(RichTextNodeType.image),
84
- data: t.intersection([
85
- ImageContentView,
86
- t.partial({
87
- linkTo: nullable(Link),
88
- }),
89
- ]),
90
- }),
91
- t.partial({
92
- label: StringOrNull,
93
- direction: StringOrNull,
94
- }),
95
- ]),
96
- )
80
+ const ImageBlockCodec = (linkCodec: LinkCodec) =>
81
+ t.exact(
82
+ t.intersection([
83
+ t.type({
84
+ type: t.literal(RichTextNodeType.image),
85
+ data: t.intersection([
86
+ ImageContentView,
87
+ t.partial({
88
+ linkTo: nullable(linkCodec),
89
+ }),
90
+ ]),
91
+ }),
92
+ t.partial({
93
+ label: StringOrNull,
94
+ direction: StringOrNull,
95
+ }),
96
+ ]),
97
+ )
98
+
99
+ export const ImageBlock = ImageBlockCodec(Link)
97
100
  export type ImageBlock = t.TypeOf<typeof ImageBlock>
101
+
102
+ const ImageBlockLegacy = ImageBlockCodec(LinkLegacy)
103
+ type ImageBlockLegacy = t.TypeOf<typeof ImageBlockLegacy>
104
+
98
105
  export function checkImageBlock(block: Block): block is ImageBlock {
99
106
  return block.type === RichTextNodeType.image
100
107
  }
@@ -196,7 +203,7 @@ type TextBlockLegacy = t.TypeOf<typeof TextBlockLegacy>
196
203
 
197
204
  const legacyBlockCodec = t.union([
198
205
  EmbedBlockLegacy,
199
- ImageBlock,
206
+ ImageBlockLegacy,
200
207
  TextBlockLegacy,
201
208
  ])
202
209
  type BlockLegacy = t.TypeOf<typeof legacyBlockCodec>
@@ -204,13 +211,14 @@ type BlockLegacy = t.TypeOf<typeof legacyBlockCodec>
204
211
  export const BlockLegacy = new t.Type<Block, BlockLegacy, unknown>(
205
212
  "BlockLegacy",
206
213
  (u): u is Block =>
207
- EmbedBlockLegacy.is(u) || ImageBlock.is(u) || TextBlockLegacy.is(u),
214
+ EmbedBlockLegacy.is(u) || ImageBlockLegacy.is(u) || TextBlockLegacy.is(u),
208
215
  (legacyBlock) => legacyBlockCodec.decode(legacyBlock),
209
216
  (block: Block) => {
210
- if (ImageBlock.is(block)) return ImageBlock.encode(block)
211
- else if (EmbedBlock.is(block))
212
- return EmbedBlockLegacy.encode(block) as BlockLegacy
213
- else return TextBlockLegacy.encode(block)
217
+ return (() => {
218
+ if (ImageBlock.is(block)) return ImageBlockLegacy.encode(block)
219
+ else if (EmbedBlock.is(block)) return EmbedBlockLegacy.encode(block)
220
+ else return TextBlockLegacy.encode(block)
221
+ })() as BlockLegacy
214
222
  },
215
223
  )
216
224
  export const Block = t.union([ImageBlock, EmbedBlock, TextBlock])
@@ -28,9 +28,7 @@ export const RichTextLegacy = (ctx: LegacyContentCtx) =>
28
28
  (u) => {
29
29
  return pipe(
30
30
  legacyReader.decode(u),
31
- either.map((r) =>
32
- RichTextContent.encode({ value: r, __TYPE__: RichTextContentType }),
33
- ),
31
+ either.map((r) => ({ value: r, __TYPE__: RichTextContentType })),
34
32
  )
35
33
  },
36
34
 
@@ -16,7 +16,10 @@ export const isSimpleSliceContent = (u: unknown): u is SimpleSliceContent =>
16
16
 
17
17
  export const SimpleSliceLegacy = (ctx: LegacyContentCtx) => {
18
18
  return {
19
- decode: (NestableLegacy(ctx) || GroupLegacy(ctx)).decode.bind(null),
19
+ decode: (() => {
20
+ if (ctx.fieldType === "Group") return GroupLegacy(ctx).decode.bind(null)
21
+ return NestableLegacy(ctx).decode.bind(null)
22
+ })(),
20
23
 
21
24
  encode: (value: SimpleSliceContent) => {
22
25
  switch (value.__TYPE__) {
@@ -9,6 +9,11 @@ import type { DynamicSlice } from "./widgets/slices/Slice"
9
9
  import type { DynamicSlices } from "./widgets/slices/Slices"
10
10
  import type { DynamicWidget } from "./widgets/Widget"
11
11
 
12
+ export const CustomTypeFormat = {
13
+ page: "page",
14
+ custom: "custom",
15
+ }
16
+
12
17
  class CustomTypeSlicesError extends Error {
13
18
  slices: Array<string>
14
19
  override message: string
@@ -41,6 +46,7 @@ function customTypeReader<T extends StaticSection | DynamicSection>(
41
46
  }),
42
47
  t.partial({
43
48
  hash: t.string,
49
+ format: withFallback(t.keyof(CustomTypeFormat), "custom"),
44
50
  }),
45
51
  ]),
46
52
  )