@prismicio/types-internal 3.0.0 → 3.1.0-alpha.0

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 (53) hide show
  1. package/lib/_internal/utils.d.ts +3 -2
  2. package/lib/content/Document.d.ts +1561 -361
  3. package/lib/content/Document.js +11 -0
  4. package/lib/content/LegacyContentCtx.d.ts +2 -2
  5. package/lib/content/LegacyContentCtx.js +4 -1
  6. package/lib/content/fields/GroupContent.js +13 -0
  7. package/lib/content/fields/RepeatableContent.d.ts +34 -40
  8. package/lib/content/fields/WidgetContent.d.ts +1558 -358
  9. package/lib/content/fields/index.d.ts +1 -0
  10. package/lib/content/fields/index.js +1 -0
  11. package/lib/content/fields/nestable/LinkContent.d.ts +122 -146
  12. package/lib/content/fields/nestable/LinkContent.js +19 -39
  13. package/lib/content/fields/nestable/NestableContent.d.ts +254 -54
  14. package/lib/content/fields/nestable/NestableContent.js +8 -1
  15. package/lib/content/fields/nestable/RichTextContent/Blocks.d.ts +66 -66
  16. package/lib/content/fields/slices/Slice/CompositeSliceContent.d.ts +510 -110
  17. package/lib/content/fields/slices/Slice/RepeatableContent.d.ts +86 -18
  18. package/lib/content/fields/slices/Slice/SharedSliceContent.d.ts +512 -112
  19. package/lib/content/fields/slices/Slice/SharedSliceContent.js +20 -4
  20. package/lib/content/fields/slices/Slice/SimpleSliceContent.d.ts +255 -55
  21. package/lib/content/fields/slices/Slice/SlicePrimaryContent.d.ts +255 -55
  22. package/lib/content/fields/slices/Slice/index.d.ts +855 -185
  23. package/lib/content/fields/slices/SliceItem.d.ts +854 -184
  24. package/lib/content/fields/slices/SlicesContent.d.ts +1278 -278
  25. package/lib/customtypes/CustomType.d.ts +18 -0
  26. package/lib/customtypes/Section.d.ts +18 -0
  27. package/lib/customtypes/diff/SharedSlice.d.ts +8 -0
  28. package/lib/customtypes/diff/Variation.d.ts +8 -0
  29. package/lib/customtypes/widgets/Group.d.ts +6 -0
  30. package/lib/customtypes/widgets/Widget.d.ts +21 -0
  31. package/lib/customtypes/widgets/nestable/Link.d.ts +10 -0
  32. package/lib/customtypes/widgets/nestable/Link.js +5 -0
  33. package/lib/customtypes/widgets/nestable/NestableWidget.d.ts +1 -0
  34. package/lib/customtypes/widgets/slices/CompositeSlice.d.ts +2 -0
  35. package/lib/customtypes/widgets/slices/LegacySlice.d.ts +2 -0
  36. package/lib/customtypes/widgets/slices/SharedSlice.d.ts +8 -0
  37. package/lib/customtypes/widgets/slices/SlicePrimaryWidget.d.ts +6 -0
  38. package/lib/customtypes/widgets/slices/Slices.d.ts +28 -0
  39. package/package.json +2 -1
  40. package/src/_internal/utils.ts +3 -1
  41. package/src/content/Document.ts +12 -0
  42. package/src/content/LegacyContentCtx.ts +4 -1
  43. package/src/content/fields/GroupContent.ts +13 -0
  44. package/src/content/fields/RepeatableContent.ts +147 -0
  45. package/src/content/fields/index.ts +1 -0
  46. package/src/content/fields/nestable/LinkContent.ts +19 -39
  47. package/src/content/fields/nestable/NestableContent.ts +12 -1
  48. package/src/content/fields/slices/Slice/SharedSliceContent.ts +18 -0
  49. package/src/customtypes/widgets/nestable/Link.ts +6 -0
  50. package/lib/content/fields/nestable/RichTextContent/TextBlock.d.ts +0 -727
  51. package/lib/content/fields/nestable/RichTextContent/TextBlock.js +0 -80
  52. package/lib/customtypes/widgets/slices/SliceWidget.d.ts +0 -327
  53. package/lib/customtypes/widgets/slices/SliceWidget.js +0 -8
@@ -97,15 +97,9 @@ export const FilledImageLinkContent = t.intersection([
97
97
  ])
98
98
  export type FilledImageLinkContent = t.TypeOf<typeof FilledImageLinkContent>
99
99
 
100
- const imageLinkLegacyCodec = t.union([
101
- t.intersection([
102
- filledImageLinkLegacyCodec,
103
- t.exact(t.partial({ text: t.string })),
104
- ]),
105
- t.strict({
106
- kind: t.literal("image"),
107
- text: t.string,
108
- }),
100
+ const imageLinkLegacyCodec = t.intersection([
101
+ t.union([filledImageLinkLegacyCodec, t.strict({ kind: t.literal("image") })]),
102
+ t.exact(t.partial({ text: t.string })),
109
103
  ])
110
104
 
111
105
  type ImageLinkLegacy = t.TypeOf<typeof imageLinkLegacyCodec>
@@ -198,15 +192,9 @@ export const FilledFileLinkContent = t.intersection([
198
192
  ])
199
193
  export type FilledFileLinkContent = t.TypeOf<typeof FilledFileLinkContent>
200
194
 
201
- const fileLinkLegacyCodec = t.union([
202
- t.intersection([
203
- filledFileLinkLegacyCodec,
204
- t.exact(t.partial({ text: t.string })),
205
- ]),
206
- t.strict({
207
- kind: t.literal("file"),
208
- text: t.string,
209
- }),
195
+ const fileLinkLegacyCodec = t.intersection([
196
+ t.union([filledFileLinkLegacyCodec, t.strict({ kind: t.literal("file") })]),
197
+ t.exact(t.partial({ text: t.string })),
210
198
  ])
211
199
 
212
200
  type FileLinkLegacy = t.TypeOf<typeof fileLinkLegacyCodec>
@@ -241,10 +229,10 @@ export type FileLinkContent = t.TypeOf<typeof FileLinkContent>
241
229
 
242
230
  export const MediaLinkType = "MediaLink"
243
231
 
244
- const mediaLinkLegacyCodec = t.strict({
245
- kind: t.literal("media"),
246
- text: t.string,
247
- })
232
+ const mediaLinkLegacyCodec = t.intersection([
233
+ t.strict({ kind: t.literal("media") }),
234
+ t.exact(t.partial({ text: t.string })),
235
+ ])
248
236
 
249
237
  type MediaLinkLegacy = t.TypeOf<typeof mediaLinkLegacyCodec>
250
238
  const MediaLinkLegacy = new t.Type<MediaLinkContent, MediaLinkLegacy>(
@@ -317,15 +305,12 @@ export type FilledDocumentLinkContent = t.TypeOf<
317
305
  typeof FilledDocumentLinkContent
318
306
  >
319
307
 
320
- const documentLinkLegacyCodec = t.union([
321
- t.intersection([
308
+ const documentLinkLegacyCodec = t.intersection([
309
+ t.union([
322
310
  filledDocumentLinkLegacyCodec,
323
- t.exact(t.partial({ text: t.string })),
311
+ t.strict({ kind: t.literal("document") }),
324
312
  ]),
325
- t.strict({
326
- kind: t.literal("document"),
327
- text: t.string,
328
- }),
313
+ t.exact(t.partial({ text: t.string })),
329
314
  ])
330
315
 
331
316
  type DocumentLinkLegacy = t.TypeOf<typeof documentLinkLegacyCodec>
@@ -409,15 +394,12 @@ export type FilledExternalLinkContent = t.TypeOf<
409
394
  typeof FilledExternalLinkContent
410
395
  >
411
396
 
412
- const externalLinkLegacyCodec = t.union([
413
- t.intersection([
397
+ const externalLinkLegacyCodec = t.intersection([
398
+ t.union([
414
399
  filledExternalLinkLegacyCodec,
415
- t.exact(t.partial({ text: t.string })),
400
+ t.strict({ kind: t.literal("web") }),
416
401
  ]),
417
- t.strict({
418
- kind: t.literal("web"),
419
- text: t.string,
420
- }),
402
+ t.exact(t.partial({ text: t.string })),
421
403
  ])
422
404
 
423
405
  type ExternalLinkLegacy = t.TypeOf<typeof externalLinkLegacyCodec>
@@ -453,9 +435,7 @@ export type ExternalLinkContent = t.TypeOf<typeof ExternalLinkContent>
453
435
 
454
436
  export const AnyLinkType = "AnyLink"
455
437
 
456
- const anyLinkLegacyCodec = t.strict({
457
- text: t.string,
458
- })
438
+ const anyLinkLegacyCodec = t.exact(t.partial({ text: t.string }))
459
439
 
460
440
  type AnyLinkLegacy = t.TypeOf<typeof anyLinkLegacyCodec>
461
441
  const AnyLinkLegacy = new t.Type<AnyLinkContent, AnyLinkLegacy>(
@@ -4,6 +4,11 @@ import * as t from "io-ts"
4
4
  import type { NestableWidget } from "../../../customtypes"
5
5
  import type { LegacyContentCtx } from "../../LegacyContentCtx"
6
6
  import { EmptyContent, EmptyLegacy, isEmptyContent } from "../EmptyContent"
7
+ import {
8
+ isRepeatableContent,
9
+ RepeatableContent,
10
+ RepeatableLegacy,
11
+ } from "../RepeatableContent"
7
12
  import {
8
13
  BooleanContent,
9
14
  BooleanContentDefaultValue,
@@ -96,6 +101,7 @@ export const NestableContent = t.union([
96
101
  LinkContent,
97
102
  RichTextContent,
98
103
  SeparatorContent,
104
+ RepeatableContent,
99
105
  ])
100
106
  export type NestableContent = t.TypeOf<typeof NestableContent>
101
107
  export type NestableContentType = NestableContent["__TYPE__"]
@@ -129,7 +135,8 @@ export const isNestableContent = (u: unknown): u is NestableContent =>
129
135
  isIntegrationFieldContent(u) ||
130
136
  isLinkContent(u) ||
131
137
  isSeparatorContent(u) ||
132
- isEmptyContent(u)
138
+ isEmptyContent(u) ||
139
+ isRepeatableContent(u)
133
140
 
134
141
  export const NestableLegacy = (ctx: LegacyContentCtx) => {
135
142
  return {
@@ -171,6 +178,8 @@ export const NestableLegacy = (ctx: LegacyContentCtx) => {
171
178
  return LinkContentLegacy(ctx)
172
179
  case "Separator":
173
180
  return SeparatorLegacy(ctx)
181
+ case "Repeatable.Link":
182
+ return RepeatableLegacy(ctx, "Link")
174
183
  default:
175
184
  return
176
185
  }
@@ -209,6 +218,8 @@ export const NestableLegacy = (ctx: LegacyContentCtx) => {
209
218
  return LinkContentLegacy(ctx).encode(value)
210
219
  case SeparatorContentType:
211
220
  return SeparatorLegacy(ctx).encode(value)
221
+ case "RepeatableContent":
222
+ return RepeatableLegacy(ctx, value.type).encode(value)
212
223
 
213
224
  default:
214
225
  return
@@ -26,6 +26,10 @@ import {
26
26
  traverseGroupItemsContent,
27
27
  } from "../../GroupContent"
28
28
  import { isNestableContent } from "../../nestable"
29
+ import {
30
+ isRepeatableContent,
31
+ traverseRepeatableContent,
32
+ } from "../../RepeatableContent"
29
33
  import {
30
34
  repeatableContentWithDefaultNestableContentValues,
31
35
  withDefaultSlicePrimaryContentValues,
@@ -215,6 +219,20 @@ export function traverseSharedSliceContent({
215
219
  content: fieldContent,
216
220
  model: fieldDef?.type === GroupFieldType ? fieldDef : undefined,
217
221
  })(transformWidget)
222
+ } else if (isRepeatableContent(fieldContent)) {
223
+ return traverseRepeatableContent({
224
+ path: path.concat([
225
+ { key: "primary", type: "primary" },
226
+ { key: fieldKey, type: "Widget" },
227
+ ]),
228
+ key: fieldKey,
229
+ apiId: fieldKey,
230
+ content: fieldContent,
231
+ model:
232
+ fieldDef?.type === "Link" && fieldDef.config?.repeat
233
+ ? fieldDef
234
+ : undefined,
235
+ })(transformWidget)
218
236
  } else if (isNestableContent(fieldContent)) {
219
237
  return transformWidget({
220
238
  path: path.concat([
@@ -79,6 +79,12 @@ export const LinkConfig = t.exact(
79
79
  tags: MasksArrayString,
80
80
  allowTargetBlank: t.boolean,
81
81
  allowText: t.boolean,
82
+
83
+ /**
84
+ * `repeat` property is used to allow multiple links to be added.
85
+ * `undefined` means that the field is not repeatable (hence repeat = false).
86
+ */
87
+ repeat: t.boolean,
82
88
  }),
83
89
  )
84
90
  export type LinkConfig = t.TypeOf<typeof LinkConfig>