@prismicio/types-internal 4.0.0 → 4.1.0-canary.18ae460

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 (117) hide show
  1. package/README.md +5 -5
  2. package/dist/content/boolean.d.ts.map +1 -1
  3. package/dist/content/boolean.js.map +1 -1
  4. package/dist/content/codec/link.js.map +1 -1
  5. package/dist/content/codec/nestable.js +4 -4
  6. package/dist/content/field.d.ts.map +1 -1
  7. package/dist/content/field.js +1 -1
  8. package/dist/content/field.js.map +1 -1
  9. package/dist/content/group.d.ts.map +1 -1
  10. package/dist/content/group.js.map +1 -1
  11. package/dist/content/image.d.ts +3 -1
  12. package/dist/content/image.d.ts.map +1 -1
  13. package/dist/content/image.js +3 -3
  14. package/dist/content/image.js.map +1 -1
  15. package/dist/content/legacy/boolean.d.ts +1 -0
  16. package/dist/content/legacy/embed.d.ts +1 -0
  17. package/dist/content/legacy/empty.d.ts +1 -0
  18. package/dist/content/legacy/field.d.ts +1 -0
  19. package/dist/content/legacy/geopoint.d.ts +1 -0
  20. package/dist/content/legacy/image.d.ts +28 -0
  21. package/dist/content/legacy/image.d.ts.map +1 -0
  22. package/dist/content/legacy/image.js +3 -3
  23. package/dist/content/legacy/image.js.map +1 -1
  24. package/dist/content/legacy/integrationField.d.ts +1 -0
  25. package/dist/content/legacy/link.d.ts +10 -10
  26. package/dist/content/legacy/link.js +23 -23
  27. package/dist/content/legacy/link.js.map +1 -1
  28. package/dist/content/legacy/nestable.d.ts +1 -0
  29. package/dist/content/legacy/nestable.js +1 -1
  30. package/dist/content/legacy/repeatable.d.ts +1 -0
  31. package/dist/content/legacy/richText.d.ts +9 -8
  32. package/dist/content/legacy/richText.d.ts.map +1 -1
  33. package/dist/content/legacy/richText.js +5 -5
  34. package/dist/content/legacy/richText.js.map +1 -1
  35. package/dist/content/legacy/separator.d.ts +1 -0
  36. package/dist/content/legacy/table.d.ts +1 -0
  37. package/dist/content/link.d.ts +62 -85
  38. package/dist/content/link.d.ts.map +1 -1
  39. package/dist/content/link.js +30 -27
  40. package/dist/content/link.js.map +1 -1
  41. package/dist/content/nestable.d.ts.map +1 -1
  42. package/dist/content/nestable.js +4 -4
  43. package/dist/content/nestable.js.map +1 -1
  44. package/dist/content/repeatable.d.ts +4 -69
  45. package/dist/content/repeatable.d.ts.map +1 -1
  46. package/dist/content/richText.d.ts +13 -13
  47. package/dist/content/richText.d.ts.map +1 -1
  48. package/dist/content/richText.js +9 -9
  49. package/dist/content/richText.js.map +1 -1
  50. package/dist/helpers/customTypeModel.d.ts +2 -1
  51. package/dist/helpers/customTypeModel.d.ts.map +1 -1
  52. package/dist/helpers/customTypeModel.js +30 -0
  53. package/dist/helpers/customTypeModel.js.map +1 -1
  54. package/dist/helpers/imageContent.d.ts +33 -0
  55. package/dist/helpers/imageContent.d.ts.map +1 -0
  56. package/dist/helpers/imageContent.js +55 -0
  57. package/dist/helpers/imageContent.js.map +1 -0
  58. package/dist/helpers/traverseContent.d.ts +4 -4
  59. package/dist/helpers/traverseContent.d.ts.map +1 -1
  60. package/dist/helpers/traverseContent.js +5 -3
  61. package/dist/helpers/traverseContent.js.map +1 -1
  62. package/dist/helpers/traverseContentWithModel.d.ts +4 -4
  63. package/dist/helpers/traverseContentWithModel.js +1 -1
  64. package/dist/helpers/withDefaultContent.d.ts +21 -0
  65. package/dist/helpers/withDefaultContent.d.ts.map +1 -0
  66. package/dist/helpers/withDefaultContent.js +120 -0
  67. package/dist/helpers/withDefaultContent.js.map +1 -0
  68. package/dist/index.d.ts +25 -22
  69. package/dist/index.js +6 -1
  70. package/dist/io-ts.d.ts +1156 -727
  71. package/dist/io-ts.d.ts.map +1 -1
  72. package/dist/io-ts.js +11 -7
  73. package/dist/io-ts.js.map +1 -1
  74. package/dist/model/richText.d.ts +20 -1
  75. package/dist/model/richText.d.ts.map +1 -1
  76. package/dist/model/richText.js +3 -3
  77. package/dist/model/richText.js.map +1 -1
  78. package/dist/model/slice.d.ts +1251 -643
  79. package/dist/model/slice.d.ts.map +1 -1
  80. package/dist/model/slice.js +4 -4
  81. package/dist/model/slice.js.map +1 -1
  82. package/dist/model/table.js +5 -5
  83. package/dist/model/table.js.map +1 -1
  84. package/dist/model/widget.d.ts +1 -3
  85. package/dist/model/widget.d.ts.map +1 -1
  86. package/dist/model/widget.js +5 -2
  87. package/dist/model/widget.js.map +1 -1
  88. package/dist/zod4.d.ts +2392 -1873
  89. package/dist/zod4.d.ts.map +1 -1
  90. package/dist/zod4.js +11 -7
  91. package/dist/zod4.js.map +1 -1
  92. package/package.json +19 -12
  93. package/src/content/boolean.ts +0 -13
  94. package/src/content/codec/link.ts +12 -12
  95. package/src/content/field.ts +0 -14
  96. package/src/content/group.ts +1 -54
  97. package/src/content/image.ts +3 -91
  98. package/src/content/legacy/image.ts +4 -4
  99. package/src/content/legacy/link.ts +46 -46
  100. package/src/content/legacy/richText.ts +18 -16
  101. package/src/content/link.ts +100 -89
  102. package/src/content/nestable.ts +1 -20
  103. package/src/content/richText.ts +23 -17
  104. package/src/helpers/customTypeModel.ts +44 -0
  105. package/src/helpers/imageContent.ts +84 -0
  106. package/src/helpers/traverseContent.ts +4 -1
  107. package/src/helpers/withDefaultContent.ts +180 -0
  108. package/src/index.ts +18 -5
  109. package/src/io-ts.ts +14 -2
  110. package/src/model/diff/sharedSlice.ts +2 -2
  111. package/src/model/diff/variation.ts +7 -7
  112. package/src/model/richText.ts +5 -2
  113. package/src/model/slice.ts +6 -8
  114. package/src/model/table.ts +5 -5
  115. package/src/model/widget.ts +6 -2
  116. package/src/zod4.ts +14 -2
  117. package/src/content/withDefaultValues.ts +0 -114
@@ -67,3 +67,47 @@ export function collectSharedSlices(
67
67
 
68
68
  return sharedSlices
69
69
  }
70
+
71
+ export function filterMissingSharedSlices<
72
+ TCustomType extends StaticCustomTypeModel | CustomTypeModel,
73
+ >(
74
+ customType: TCustomType,
75
+ sharedSlices: Map<string, SharedSliceModel> | Record<string, SharedSliceModel>,
76
+ ): TCustomType {
77
+ const json: TCustomType["json"] = {}
78
+
79
+ const sharedSlicesMap =
80
+ sharedSlices instanceof Map ? sharedSlices : new Map(Object.entries(sharedSlices))
81
+
82
+ for (const [tabKey, tab] of Object.entries(customType.json)) {
83
+ const tabJSON: typeof tab = {}
84
+ for (const [key, widget] of Object.entries(tab)) {
85
+ switch (widget.type) {
86
+ case "Slices":
87
+ case "Choice":
88
+ const choices: Required<typeof widget>["config"]["choices"] = {}
89
+ for (const [id, model] of Object.entries(widget.config?.choices || {})) {
90
+ if (model.type === "SharedSlice") {
91
+ if (sharedSlicesMap.get(id)) {
92
+ choices[id] = model
93
+ }
94
+ } else {
95
+ choices[id] = model
96
+ }
97
+ }
98
+
99
+ tabJSON[key] = {
100
+ ...widget,
101
+ config: { ...widget.config, choices },
102
+ }
103
+ break
104
+ default:
105
+ tabJSON[key] = widget
106
+ }
107
+ }
108
+
109
+ json[tabKey] = tabJSON
110
+ }
111
+
112
+ return { ...customType, json }
113
+ }
@@ -0,0 +1,84 @@
1
+ import type { ImageContent, ImageContentView } from "../content/image"
2
+
3
+ export interface CroppedImage {
4
+ zoom: number
5
+ /** X coordinate of the crop rect on the original image */
6
+ x: number
7
+ /** Y coordinate of the crop rect on the original image */
8
+ y: number
9
+
10
+ /** The width of the crop rect over the original image */
11
+ cropWidth: number
12
+ /** The height of the crop rect over the original image */
13
+ cropHeight: number
14
+
15
+ /** Final (user defined via W input) width of the image */
16
+ width: number
17
+ /** Final (user defined via H input) height of the image */
18
+ height: number
19
+ }
20
+
21
+ export function buildCropURL(args: {
22
+ origin: ImageContent["origin"]
23
+ croppedImage: CroppedImage
24
+ }): string {
25
+ const { origin, croppedImage } = args
26
+ const { x, y, width, height, cropHeight, cropWidth } = croppedImage
27
+
28
+ const url = new URL(origin.url)
29
+
30
+ const hasResize = origin.height !== height || origin.width !== width
31
+
32
+ const hasCrop = x !== 0 || y !== 0 || cropHeight !== origin.height || cropWidth !== origin.width
33
+
34
+ if (hasCrop) {
35
+ const crop = [x, y, cropWidth, cropHeight].map(Math.round).join(",")
36
+
37
+ url.searchParams.set("rect", crop)
38
+ url.searchParams.set("w", width.toString())
39
+ url.searchParams.set("h", height.toString())
40
+ }
41
+
42
+ if (hasResize) {
43
+ url.searchParams.set("w", width.toString())
44
+ url.searchParams.set("h", height.toString())
45
+ }
46
+
47
+ return url.toString()
48
+ }
49
+
50
+ export function getCroppedImage({ contentView }: { contentView: ImageContentView }): CroppedImage {
51
+ const {
52
+ edit: {
53
+ crop: { x, y },
54
+ zoom,
55
+ },
56
+ width,
57
+ height,
58
+ origin: { width: originWidth, height: originHeight },
59
+ } = contentView
60
+
61
+ let cropWidth
62
+ let cropHeight
63
+ const originAspect = originWidth / originHeight
64
+ const cropAspect = width / height
65
+ if (cropAspect >= originAspect) {
66
+ // crop and origin image would be the same width if zoom was equal to 1
67
+ cropWidth = originWidth / zoom
68
+ cropHeight = cropWidth / cropAspect
69
+ } else {
70
+ // crop and origin image would be the same height if zoom was equal to 1
71
+ cropHeight = originHeight / zoom
72
+ cropWidth = cropHeight * cropAspect
73
+ }
74
+
75
+ return {
76
+ x,
77
+ y,
78
+ width,
79
+ height,
80
+ zoom,
81
+ cropWidth,
82
+ cropHeight,
83
+ }
84
+ }
@@ -332,7 +332,10 @@ export function traverseLegacySliceContent(
332
332
  }
333
333
  } else {
334
334
  if (model?.type === "SharedSlice") {
335
- legacySliceModel = model.fields.primary?.[content.name]
335
+ const primaryModel = model.fields.primary?.[content.name]
336
+ if (primaryModel?.type !== "Group") {
337
+ legacySliceModel = primaryModel
338
+ }
336
339
  } else if (model?.type !== "Group") {
337
340
  legacySliceModel = model
338
341
  }
@@ -0,0 +1,180 @@
1
+ import { BooleanContentType } from "../content/boolean"
2
+ import type { DocumentContent } from "../content/document"
3
+ import { FieldContentType, SelectFieldType } from "../content/field"
4
+ import type { GroupContent, GroupItemContent } from "../content/group"
5
+ import { GroupContentType } from "../content/group"
6
+ import type { SliceContent } from "../content/slice"
7
+ import { CompositeSliceContentType, SharedSliceContentType } from "../content/slice"
8
+ import type { SlicesContent } from "../content/slices"
9
+ import { SlicesContentType } from "../content/slices"
10
+ import type { WidgetContent } from "../content/widget"
11
+ import type { StaticCustomTypeModel } from "../model/customType"
12
+ import type { GroupModel } from "../model/group"
13
+ import type { NestableModel } from "../model/nestable"
14
+ import type { StaticSliceModel } from "../model/slice"
15
+ import type { StaticWidgetModel } from "../model/widget"
16
+ import * as customTypeModel from "./customTypeModel"
17
+
18
+ export function document(content: DocumentContent, model: StaticCustomTypeModel): DocumentContent {
19
+ return record(content, customTypeModel.flatten(model))
20
+ }
21
+
22
+ export function slice(content: SliceContent, model: StaticSliceModel | undefined): SliceContent {
23
+ if (!model) {
24
+ return content
25
+ }
26
+
27
+ if (model.type === "SharedSlice") {
28
+ if (content.__TYPE__ !== SharedSliceContentType) {
29
+ return content
30
+ }
31
+
32
+ const variation = model.variations.find((variation) => variation.id === content.variation)
33
+ if (!variation) {
34
+ return content
35
+ }
36
+
37
+ return {
38
+ ...content,
39
+ primary: record(content.primary, variation?.primary),
40
+ items: items(content.items, variation?.items),
41
+ }
42
+ }
43
+
44
+ if (model.type === "Slice") {
45
+ if (content.__TYPE__ !== CompositeSliceContentType) {
46
+ return content
47
+ }
48
+
49
+ return {
50
+ ...content,
51
+ nonRepeat: record(content.nonRepeat, model["non-repeat"]),
52
+ repeat: items(content.repeat, model.repeat),
53
+ }
54
+ }
55
+
56
+ if (
57
+ content.__TYPE__ === SharedSliceContentType ||
58
+ content.__TYPE__ === CompositeSliceContentType
59
+ ) {
60
+ return content
61
+ }
62
+
63
+ return widget(content, model)
64
+ }
65
+
66
+ export function widget<TContent extends WidgetContent | undefined>(
67
+ content: TContent,
68
+ model: StaticWidgetModel | undefined,
69
+ ): TContent {
70
+ if (!model) {
71
+ return content
72
+ }
73
+
74
+ if (
75
+ (model.type === "Slices" || model.type === "Choice") &&
76
+ content?.__TYPE__ === SlicesContentType
77
+ ) {
78
+ if (!model.config?.choices) return content
79
+
80
+ const value: SlicesContent["value"] = []
81
+ for (const sliceItem of content.value) {
82
+ value.push({
83
+ ...sliceItem,
84
+ widget: slice(sliceItem.widget, model.config.choices[sliceItem.name]),
85
+ })
86
+ }
87
+
88
+ return { ...content, value }
89
+ }
90
+
91
+ if (model.type === "Group") {
92
+ if (content?.__TYPE__ !== GroupContentType) {
93
+ return <TContent>{
94
+ __TYPE__: GroupContentType,
95
+ value: items([], model.config?.fields),
96
+ }
97
+ }
98
+
99
+ return { ...content, value: items(content.value, model.config?.fields) }
100
+ }
101
+
102
+ if (model.type === "Boolean" && !content) {
103
+ if (model.config?.default_value === undefined) {
104
+ return <TContent>undefined
105
+ }
106
+
107
+ return <TContent>{
108
+ __TYPE__: BooleanContentType,
109
+ value: model.config.default_value,
110
+ }
111
+ }
112
+
113
+ if (model.type === "Select" && !content) {
114
+ if (!model.config?.default_value) {
115
+ return <TContent>undefined
116
+ }
117
+
118
+ return <TContent>{
119
+ __TYPE__: FieldContentType,
120
+ type: SelectFieldType,
121
+ value: model.config.default_value,
122
+ }
123
+ }
124
+
125
+ return content
126
+ }
127
+
128
+ export function items(
129
+ items: GroupContent["value"],
130
+ fields: Record<string, GroupModel | NestableModel> | undefined,
131
+ ): GroupContent["value"] {
132
+ if (!fields) {
133
+ return items
134
+ }
135
+
136
+ const itemsWithDefaults: GroupContent["value"] = []
137
+ for (const item of items) {
138
+ const itemValue: GroupItemContent["value"] = []
139
+
140
+ const missingFields = { ...fields }
141
+ for (const [key, value] of item.value) {
142
+ delete missingFields[key]
143
+ itemValue.push([key, widget(value, fields[key])])
144
+ }
145
+ for (const [key, field] of Object.entries(missingFields)) {
146
+ const content = widget(undefined, field)
147
+ if (content) {
148
+ itemValue.push([key, content])
149
+ }
150
+ }
151
+
152
+ itemsWithDefaults.push({ ...item, value: itemValue })
153
+ }
154
+
155
+ return itemsWithDefaults
156
+ }
157
+
158
+ function record<TContent extends WidgetContent>(
159
+ record: Record<string, TContent>,
160
+ fields: Record<string, StaticWidgetModel> | undefined,
161
+ ): Record<string, TContent> {
162
+ if (!fields) {
163
+ return record
164
+ }
165
+
166
+ const missingFields = { ...fields }
167
+ const recordWithDefaults: Record<string, TContent> = {}
168
+ for (const [key, value] of Object.entries(record)) {
169
+ delete missingFields[key]
170
+ recordWithDefaults[key] = widget(value, fields[key])
171
+ }
172
+ for (const [key, field] of Object.entries(missingFields)) {
173
+ const content = widget(undefined, field)
174
+ if (content) {
175
+ recordWithDefaults[key] = content
176
+ }
177
+ }
178
+
179
+ return recordWithDefaults
180
+ }
package/src/index.ts CHANGED
@@ -22,12 +22,21 @@ export type {
22
22
  } from "./content/field"
23
23
  export type { GeoPointContent } from "./content/geopoint"
24
24
  export type { GroupContent, GroupItemContent } from "./content/group"
25
- export type { ImageContent } from "./content/image"
25
+ export type { ImageContent, ImageContentView } from "./content/image"
26
26
  export type { IntegrationFieldContent } from "./content/integrationField"
27
- export type { LinkContent } from "./content/link"
27
+ export type { EmptyLinkContent, FilledLinkContent, LinkContent } from "./content/link"
28
28
  export type { NestableContent } from "./content/nestable"
29
29
  export type { RepeatableContent } from "./content/repeatable"
30
- export type { RichTextContent, RichTextContentBlock, RichTextContentSpan } from "./content/richText"
30
+ export type {
31
+ RichTextContent,
32
+ RichTextContentBlock,
33
+ RichTextContentTextBlock,
34
+ RichTextContentImageBlock,
35
+ RichTextContentEmbedBlock,
36
+ RichTextContentSpan,
37
+ RichTextNodeTypes,
38
+ } from "./content/richText"
39
+ export { RichTextNodeType } from "./content/richText"
31
40
  export type { SeparatorContent } from "./content/separator"
32
41
  export type {
33
42
  LegacySliceContent,
@@ -60,7 +69,8 @@ export type { LinkModel } from "./model/link"
60
69
  export type { NestableModel } from "./model/nestable"
61
70
  export type { NumberModel } from "./model/number"
62
71
  export type { RangeModel } from "./model/range"
63
- export type { RichTextModel } from "./model/richText"
72
+ export type { RichTextModel, RichTextModelNodeTypes } from "./model/richText"
73
+ export { RichTextModelNodeType } from "./model/richText"
64
74
  export type { StaticSectionModel, DynamicSectionModel } from "./model/section"
65
75
  export type { SelectModel } from "./model/select"
66
76
  export type { SeparatorModel } from "./model/separator"
@@ -69,7 +79,8 @@ export type {
69
79
  CompositeSliceModel,
70
80
  SharedSliceModel,
71
81
  SharedSliceRefModel,
72
- SharedSliceVariationContentModel as SharedSliceVariationModel,
82
+ SharedSliceModelVariation,
83
+ SharedSliceVariationContentModel,
73
84
  StaticSliceModel,
74
85
  DynamicSliceModel,
75
86
  SliceContentModel,
@@ -91,6 +102,8 @@ export * as contentPath from "./helpers/contentPath"
91
102
  export * as customTypeModel from "./helpers/customTypeModel"
92
103
  export * as documentContent from "./helpers/documentContent"
93
104
  export * as sliceContent from "./helpers/sliceContent"
105
+ export * as withDefaultContent from "./helpers/withDefaultContent"
106
+ export * as imageContent from "./helpers/imageContent"
94
107
  export {
95
108
  traverseDocumentContent,
96
109
  traverseSlicesContent,
package/src/io-ts.ts CHANGED
@@ -60,9 +60,16 @@ import {
60
60
  GroupContentSchema as rawGroupContentSchema,
61
61
  GroupItemContentSchema as rawGroupItemContentSchema,
62
62
  } from "./content/group"
63
- import { ImageContentSchema as rawImageContentSchema } from "./content/image"
63
+ import {
64
+ ImageContentSchema as rawImageContentSchema,
65
+ ImageContentViewSchema as rawImageContentViewSchema,
66
+ } from "./content/image"
64
67
  import { IntegrationFieldContentSchema as rawIntegrationFieldContentSchema } from "./content/integrationField"
65
- import { LinkContentSchema as rawLinkContentSchema } from "./content/link"
68
+ import {
69
+ EmptyLinkContentSchema as rawEmptyLinkContentSchema,
70
+ FilledLinkContentSchema as rawFilledLinkContentSchema,
71
+ LinkContentSchema as rawLinkContentSchema,
72
+ } from "./content/link"
66
73
  import { NestableContentSchema as rawNestableContentSchema } from "./content/nestable"
67
74
  import { RepeatableContentSchema as rawRepeatableContentSchema } from "./content/repeatable"
68
75
  import {
@@ -118,6 +125,7 @@ import {
118
125
  LegacySliceModelSchema as rawLegacySliceModelSchema,
119
126
  CompositeSliceModelSchema as rawCompositeSliceModelSchema,
120
127
  SharedSliceModelSchema as rawSharedSliceModelSchema,
128
+ SharedSliceModelVariationSchema as rawSharedSliceModelVariationSchema,
121
129
  SharedSliceRefModelSchema as rawSharedSliceRefModelSchema,
122
130
  StaticSliceModelSchema as rawStaticSliceModelSchema,
123
131
  DynamicSliceModelSchema as rawDynamicSliceModelSchema,
@@ -149,6 +157,8 @@ export const ColorContentSchema = toIOTS(rawColorContentSchema)
149
157
  export const DateContentSchema = toIOTS(rawDateContentSchema)
150
158
  export const EmptyContentSchema = toIOTS(rawEmptyContentSchema)
151
159
  export const GeoPointContentSchema = toIOTS(rawGeoPointContentSchema)
160
+ export const FilledLinkContentSchema = toIOTS(rawFilledLinkContentSchema)
161
+ export const EmptyLinkContentSchema = toIOTS(rawEmptyLinkContentSchema)
152
162
  export const LinkContentSchema = toIOTS(rawLinkContentSchema)
153
163
  export const NumberContentSchema = toIOTS(rawNumberContentSchema)
154
164
  export const RangeContentSchema = toIOTS(rawRangeContentSchema)
@@ -161,6 +171,7 @@ export const FieldContentSchema = toIOTS(rawFieldContentSchema)
161
171
  export const UIDContentSchema = toIOTS(rawUIDContentSchema)
162
172
  export const IntegrationFieldContentSchema = toIOTS(rawIntegrationFieldContentSchema)
163
173
  export const EmbedContentSchema = toIOTS(rawEmbedContentSchema)
174
+ export const ImageContentViewSchema = toIOTS(rawImageContentViewSchema)
164
175
  export const ImageContentSchema = toIOTS(rawImageContentSchema)
165
176
  export const RichTextContentSchema = toIOTS(rawRichTextContentSchema)
166
177
  export const RichTextContentBlockSchema = toIOTS(rawRichTextContentBlockSchema)
@@ -235,6 +246,7 @@ export const TimestampModelSchema = toIOTS(rawTimestampModelSchema)
235
246
  export const UIDModelSchema = toIOTS(rawUIDModelSchema)
236
247
  export const GroupModelSchema = toIOTS(rawGroupModelSchema)
237
248
  export const NestedGroupModelSchema = toIOTS(rawNestedGroupModelSchema)
249
+ export const SharedSliceModelVariationSchema = toIOTS(rawSharedSliceModelVariationSchema)
238
250
  export const SharedSliceRefModelSchema = toIOTS(rawSharedSliceRefModelSchema)
239
251
  export const CompositeSliceModelSchema = toIOTS(rawCompositeSliceModelSchema)
240
252
  export const LegacySliceModelSchema = toIOTS(rawLegacySliceModelSchema)
@@ -1,4 +1,4 @@
1
- import type { SharedSliceModel, SharedSliceVariation } from "../slice"
1
+ import type { SharedSliceModel, SharedSliceModelVariation } from "../slice"
2
2
  import { type DiffChange, DiffOperation } from "./changes"
3
3
  import { isNotEmpty, toRecord, zipObjects } from "./utils"
4
4
  import { type VariationDiff, VariationComparator } from "./variation"
@@ -41,7 +41,7 @@ export const SliceComparator = {
41
41
 
42
42
  const diffMeta = compareSliceMeta(sliceA, sliceB)
43
43
 
44
- const zippedSlices = zipObjects<SharedSliceVariation>(
44
+ const zippedSlices = zipObjects<SharedSliceModelVariation>(
45
45
  sliceA && toRecord(sliceA.variations, (v) => v.id),
46
46
  sliceB && toRecord(sliceB.variations, (v) => v.id),
47
47
  )
@@ -1,7 +1,7 @@
1
1
  import type { GroupModel } from "../group"
2
2
  import { GroupFieldType } from "../group"
3
3
  import type { NestableModel } from "../nestable"
4
- import type { SharedSliceVariation } from "../slice"
4
+ import type { SharedSliceModelVariation } from "../slice"
5
5
  import { type DiffChange, DiffOperation } from "./changes"
6
6
  import { isNotEmpty, zipObjects } from "./utils"
7
7
  import type {
@@ -10,9 +10,9 @@ import type {
10
10
  SlicePrimaryWidgetDiff,
11
11
  } from "./widgets"
12
12
 
13
- export type VariationMetadata = Omit<SharedSliceVariation, "primary" | "items">
13
+ export type VariationMetadata = Omit<SharedSliceModelVariation, "primary" | "items">
14
14
  export type VariationDiff = DiffChange<
15
- SharedSliceVariation,
15
+ SharedSliceModelVariation,
16
16
  Partial<VariationMetadata> & {
17
17
  primary?: Record<string, SlicePrimaryWidgetDiff>
18
18
  items?: Record<string, NestableWidgetDiff>
@@ -20,8 +20,8 @@ export type VariationDiff = DiffChange<
20
20
  >
21
21
 
22
22
  function compareVariationMeta(
23
- variationA?: SharedSliceVariation,
24
- variationB?: SharedSliceVariation,
23
+ variationA?: SharedSliceModelVariation,
24
+ variationB?: SharedSliceModelVariation,
25
25
  ): Partial<VariationMetadata> {
26
26
  const zippedVariations = zipObjects(variationA, variationB)
27
27
 
@@ -119,8 +119,8 @@ function compareWidgets<TWidget extends NestableModel | GroupModel>(
119
119
 
120
120
  export const VariationComparator = {
121
121
  compare(
122
- variationA?: SharedSliceVariation,
123
- variationB?: SharedSliceVariation,
122
+ variationA?: SharedSliceModelVariation,
123
+ variationB?: SharedSliceModelVariation,
124
124
  ): VariationDiff | undefined {
125
125
  if (variationA && !variationB)
126
126
  return {
@@ -6,7 +6,7 @@ export const RichTextFieldType = "StructuredText"
6
6
 
7
7
  export const DEFAULT_OPTION = "paragraph"
8
8
 
9
- export const RichTextNodeType = {
9
+ export const RichTextModelNodeType = {
10
10
  heading1: "heading1",
11
11
  heading2: "heading2",
12
12
  heading3: "heading3",
@@ -25,7 +25,10 @@ export const RichTextNodeType = {
25
25
  rtl: "rtl",
26
26
  } as const
27
27
 
28
- const VALID_NODE_TYPES = Object.values(RichTextNodeType)
28
+ export type RichTextModelNodeTypes =
29
+ (typeof RichTextModelNodeType)[keyof typeof RichTextModelNodeType]
30
+
31
+ const VALID_NODE_TYPES = Object.values(RichTextModelNodeType)
29
32
 
30
33
  /**
31
34
  * RichTextOptions parses comma-separated node types, filters invalid ones,
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod/mini"
2
2
 
3
3
  import { WidgetKeySchema } from "../common/widgetKey"
4
- import type { NestedGroupModel } from "./group"
4
+ import type { GroupModel, NestedGroupModel } from "./group"
5
5
  import { GroupModelSchema, NestedGroupModelSchema } from "./group"
6
6
  import type { NestableModel } from "./nestable"
7
7
  import { NestableModelSchema } from "./nestable"
@@ -40,7 +40,7 @@ export const SharedSliceType = "SharedSlice" as const
40
40
  const IMAGE_PLACEHOLDER_URL =
41
41
  "https://images.prismic.io/slice-machine/621a5ec4-0387-4bc5-9860-2dd46cbc07cd_default_ss.png?auto=compress,format"
42
42
 
43
- export const SharedSliceVariationSchema = z.object({
43
+ export const SharedSliceModelVariationSchema = z.object({
44
44
  id: z.string(),
45
45
  name: z.string(),
46
46
  description: z.string(),
@@ -51,21 +51,19 @@ export const SharedSliceVariationSchema = z.object({
51
51
  primary: z.optional(
52
52
  z.record(
53
53
  z.string(),
54
- z.union([NestableModelSchema, GroupModelSchema]) as z.ZodMiniType<
55
- NestableModel | NestedGroupModel
56
- >,
54
+ z.union([NestableModelSchema, GroupModelSchema]) as z.ZodMiniType<NestableModel | GroupModel>,
57
55
  ),
58
56
  ),
59
57
  items: z.optional(z.record(z.string(), NestableModelSchema)),
60
58
  })
61
59
 
62
- export type SharedSliceVariation = z.infer<typeof SharedSliceVariationSchema>
60
+ export type SharedSliceModelVariation = z.infer<typeof SharedSliceModelVariationSchema>
63
61
 
64
62
  export const SharedSliceModelSchema = z.object({
65
63
  id: z.string(),
66
64
  type: z.literal(SharedSliceType),
67
65
  name: z.string(),
68
- variations: z.array(SharedSliceVariationSchema),
66
+ variations: z.array(SharedSliceModelVariationSchema),
69
67
  description: z.optional(z.string()),
70
68
  legacyPaths: z.optional(z.record(z.string(), z.string())),
71
69
  })
@@ -84,7 +82,7 @@ export const SharedSliceVariationContentModelSchema = z.object({
84
82
  type: z.literal(SharedSliceType),
85
83
  sliceName: z.string(),
86
84
  variationID: z.string(),
87
- fields: z.pick(SharedSliceVariationSchema, { primary: true, items: true }),
85
+ fields: z.pick(SharedSliceModelVariationSchema, { primary: true, items: true }),
88
86
  })
89
87
 
90
88
  export type SharedSliceVariationContentModel = z.infer<
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod/mini"
2
2
 
3
- import { RichTextNodeType, type RichTextModel } from "./richText"
3
+ import { RichTextModelNodeType, type RichTextModel } from "./richText"
4
4
 
5
5
  const TableConfigSchema = z.object({
6
6
  label: z.nullish(z.string()),
@@ -15,10 +15,10 @@ export type TableModel = z.infer<typeof TableModelSchema>
15
15
 
16
16
  // TableCell configuration constant (used for cell rich text configuration)
17
17
  export const TableCellModelNodeTypes = [
18
- RichTextNodeType.paragraph,
19
- RichTextNodeType.strong,
20
- RichTextNodeType.em,
21
- RichTextNodeType.hyperlink,
18
+ RichTextModelNodeType.paragraph,
19
+ RichTextModelNodeType.strong,
20
+ RichTextModelNodeType.em,
21
+ RichTextModelNodeType.hyperlink,
22
22
  ]
23
23
 
24
24
  export const TableCellModel: RichTextModel = {
@@ -46,7 +46,6 @@ export const FieldModelTypeSchema = z.enum([
46
46
  "Text",
47
47
  "Timestamp",
48
48
  "Link",
49
- "Repeatable.Link",
50
49
  "Image",
51
50
  "IntegrationFields",
52
51
  "UID",
@@ -58,6 +57,11 @@ export const FieldModelTypeSchema = z.enum([
58
57
  export type FieldModelType = z.infer<typeof FieldModelTypeSchema>
59
58
 
60
59
  // Field and slice types
61
- export const FieldOrSliceTypeSchema = z.union([FieldModelTypeSchema, SliceModelTypeSchema])
60
+ export const FieldOrSliceTypeSchema = z.union([
61
+ FieldModelTypeSchema,
62
+ SliceModelTypeSchema,
63
+ // Repeatable links are "meta" types like slices and shared slices
64
+ z.literal("Repeatable.Link"),
65
+ ])
62
66
 
63
67
  export type FieldOrSliceType = z.infer<typeof FieldOrSliceTypeSchema>
package/src/zod4.ts CHANGED
@@ -24,9 +24,16 @@ import {
24
24
  GroupContentSchema as rawGroupContentSchema,
25
25
  GroupItemContentSchema as rawGroupItemContentSchema,
26
26
  } from "./content/group"
27
- import { ImageContentSchema as rawImageContentSchema } from "./content/image"
27
+ import {
28
+ ImageContentSchema as rawImageContentSchema,
29
+ ImageContentViewSchema as rawImageContentViewSchema,
30
+ } from "./content/image"
28
31
  import { IntegrationFieldContentSchema as rawIntegrationFieldContentSchema } from "./content/integrationField"
29
- import { LinkContentSchema as rawLinkContentSchema } from "./content/link"
32
+ import {
33
+ EmptyLinkContentSchema as rawEmptyLinkContentSchema,
34
+ FilledLinkContentSchema as rawFilledLinkContentSchema,
35
+ LinkContentSchema as rawLinkContentSchema,
36
+ } from "./content/link"
30
37
  import { NestableContentSchema as rawNestableContentSchema } from "./content/nestable"
31
38
  import { RepeatableContentSchema as rawRepeatableContentSchema } from "./content/repeatable"
32
39
  import {
@@ -82,6 +89,7 @@ import {
82
89
  LegacySliceModelSchema as rawLegacySliceModelSchema,
83
90
  CompositeSliceModelSchema as rawCompositeSliceModelSchema,
84
91
  SharedSliceModelSchema as rawSharedSliceModelSchema,
92
+ SharedSliceModelVariationSchema as rawSharedSliceModelVariationSchema,
85
93
  SharedSliceRefModelSchema as rawSharedSliceRefModelSchema,
86
94
  StaticSliceModelSchema as rawStaticSliceModelSchema,
87
95
  DynamicSliceModelSchema as rawDynamicSliceModelSchema,
@@ -113,6 +121,8 @@ export const ColorContentSchema = toZod4(rawColorContentSchema)
113
121
  export const DateContentSchema = toZod4(rawDateContentSchema)
114
122
  export const EmptyContentSchema = toZod4(rawEmptyContentSchema)
115
123
  export const GeoPointContentSchema = toZod4(rawGeoPointContentSchema)
124
+ export const FilledLinkContentSchema = toZod4(rawFilledLinkContentSchema)
125
+ export const EmptyLinkContentSchema = toZod4(rawEmptyLinkContentSchema)
116
126
  export const LinkContentSchema = toZod4(rawLinkContentSchema)
117
127
  export const NumberContentSchema = toZod4(rawNumberContentSchema)
118
128
  export const RangeContentSchema = toZod4(rawRangeContentSchema)
@@ -125,6 +135,7 @@ export const FieldContentSchema = toZod4(rawFieldContentSchema)
125
135
  export const UIDContentSchema = toZod4(rawUIDContentSchema)
126
136
  export const IntegrationFieldContentSchema = toZod4(rawIntegrationFieldContentSchema)
127
137
  export const EmbedContentSchema = toZod4(rawEmbedContentSchema)
138
+ export const ImageContentViewSchema = toZod4(rawImageContentViewSchema)
128
139
  export const ImageContentSchema = toZod4(rawImageContentSchema)
129
140
  export const RichTextContentSchema = toZod4(rawRichTextContentSchema)
130
141
  export const RichTextContentBlockSchema = toZod4(rawRichTextContentBlockSchema)
@@ -167,6 +178,7 @@ export const TimestampModelSchema = toZod4(rawTimestampModelSchema)
167
178
  export const UIDModelSchema = toZod4(rawUIDModelSchema)
168
179
  export const GroupModelSchema = toZod4(rawGroupModelSchema)
169
180
  export const NestedGroupModelSchema = toZod4(rawNestedGroupModelSchema)
181
+ export const SharedSliceModelVariationSchema = toZod4(rawSharedSliceModelVariationSchema)
170
182
  export const SharedSliceRefModelSchema = toZod4(rawSharedSliceRefModelSchema)
171
183
  export const CompositeSliceModelSchema = toZod4(rawCompositeSliceModelSchema)
172
184
  export const LegacySliceModelSchema = toZod4(rawLegacySliceModelSchema)